WebAssembly/stringref

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

Liedtke opened this issue · 4 comments

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.

Totally agree. See my previous proposal about that #37

gkdn commented

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

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 commented

Sounds good to keep it consistent with the rest.