-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
Implement JSString to reduce bridging overhead #63
Conversation
/// - lhs: A string to compare. | ||
/// - rhs: Another string to compare. | ||
public static func == (lhs: JSString, rhs: JSString) -> Bool { | ||
return lhs.guts.buffer == rhs.guts.buffer |
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.
Could there be a way to run this comparison on the JS side, without potentially triggering copies?
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.
That's a trade-off point. If we compare them in JS side, it may trigger copies and re-encode Swift string to JS
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.
Does it make sense to add a flag to Guts that reports whether the value is cached in Swift? That way it would be possible to do the check in JS if neither string is cached in Swift.
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.
Great stuff! 👏
}() | ||
|
||
lazy var buffer: String = { | ||
var bytesRef: JavaScriptObjectRef = 0 |
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.
var bytesRef: JavaScriptObjectRef = 0 | |
var bytesRef = JavaScriptObjectRef() |
/// - lhs: A string to compare. | ||
/// - rhs: Another string to compare. | ||
public static func == (lhs: JSString, rhs: JSString) -> Bool { | ||
return lhs.guts.buffer == rhs.guts.buffer |
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.
Does it make sense to add a flag to Guts that reports whether the value is cached in Swift? That way it would be possible to do the check in JS if neither string is cached in Swift.
Before
After