-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support JS IR target #151
Support JS IR target #151
Conversation
ce62175
to
1806ed0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor questions, mainly for future, not really necessary for now :)
|
||
import kotlinx.io.internal.commonAsUtf8ToByteArray | ||
|
||
internal actual fun String.asUtf8ToByteArray(): ByteArray = commonAsUtf8ToByteArray() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: can't we just use String.encodeToByteArray(): ByteArray
on all platforms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It (encodeToByteArray
) behaves differently on JVM and Native when encoding invalid code points (and I'll revisit its usage in ByteString
's).
|
||
package kotlinx.io | ||
|
||
internal actual object SegmentPool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: will JS/Native have pooling some day? If so may be it's better to create an issue for this. Or this will be implemented in scope of #135/different segment types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be considered after #135 (I expect to see the performance improvement on Native w/ enabled pooling, but I didn't measure it yet).
} | ||
val bytesToRead = minOf(byteCount, (len - offset)) | ||
for (i in 0 until bytesToRead) { | ||
sink.writeByte(buffer.readInt8(offset++) as Byte) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: we can do bulk copy here: https://nodejs.org/api/buffer.html#bufcopytarget-targetstart-sourcestart-sourceend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Buffer::copy
expects Buffer
or UInt8Array
as the destination, and Segment's backing array (Segment::data
) is an instance of Int8Array
.
I think the issue could be addressed later, after #135
Supported JS-IR target.
Closes #141