Skip to content

compliance of a sort optimization #2307

Open
@jmdyck

Description

@jmdyck

In Array.p.sort, if _comparefn_ is *undefined*, items are compared by comparing their ToString results. Rather than calling ToString twice per call to SortCompare, it seems like an implementation might want to call ToString on each item exactly once, sort the resulting strings, and then arrange the original items accordingly (aka the decorate-sort-undecorate pattern).

However, calls to ToString can be observed, and this optimization would definitely change the number of those calls (from roughly 2 n log(n) to just n). So does that mean that this optimization is non-compliant? (If so, do implementations use it anyway?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions