Skip to content
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

New three-way string comparison instruction similar to std::strcmp in C++ #58

Open
Liedtke opened this issue Jan 25, 2023 · 4 comments
Open

Comments

@Liedtke
Copy link

Liedtke commented Jan 25, 2023

For performance evaluations we added the following instruction to v8 (change) and it might make sense to add it to the stringref proposal:

  • string.compare [0xfba8]
  • returns -1, 0 or 1 if the compared strings are lessThan, equal or greaterThan
  • traps if either of the inputs is null

The instruction does not use locale-specific comparisons but behaves like the operator < / > in JavaScript to determine the order.

@MaxGraey
Copy link

MaxGraey commented Jan 25, 2023

Totally agree. See my previous proposal about that #37

@gkdn
Copy link

gkdn commented Feb 15, 2023

I can't remember other instructions maybe we should require this to accept non-nullable string?

@jakobkummerow
Copy link
Collaborator

Prior discussion: #47

I couldn't find a reference for it, but I thought I remembered a decision to follow the example of struct.get and similar to accept nullable types. It probably doesn't make a big difference in practice, because it's easy even for simple decoders to omit null checks when the input type is already known to be non-null. (Personally I don't mind either way: I'd be fine with making the entire stringref proposal non-nullable; I'm also fine with keeping things as they are.)

@gkdn
Copy link

gkdn commented Feb 15, 2023

Sounds good to keep it consistent with the rest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants