Skip to content

JS String.cmp rebuilds both input strings while finding their order #1701

Closed as not planned

Description

@oxura

String.cmp returns both original strings along with their order, but its JS Base path recursively reconstructs those strings even though the host representation is immutable text.

For an exported wrapper returning (String & String) & Cmp, I compared two strings with a 256-character common prefix, 100 calls per round. Nine warmed alternating rounds: median 4.771 ms before, 0.140 ms after, with the same LT results and both returned texts unchanged. Linux x64/Bun 1.3.13, existing #1682 head 0b82c20 versus the patch.

The lowering reuses string_compare already in that PR and returns the two original host strings. It does not substitute JS UTF-16 lexical order: full U32 Chars, packed non-scalars and astral characters still use numeric Char order. The updated runtime fixture checks both returned strings through their Char codes, including U+0000, a surrogate, U+10000 and U32 max.

Patch: oxura@aa331dfd
Included in existing PR #1682; the earlier String.order/eq reports are not being counted again.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions