View source code
Display the source code in dmd/expression.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function dmd.expression.StringExp.compare

Compare two StringExp by length, then value

extern(C++) int compare (
  const(StringExp) se2
) pure nothrow @nogc const;

The comparison is not the usual C-style comparison as seen with strcmp or memcmp, but instead first compare based on the length. This allows both faster lookup and sorting when comparing sparse data.

This ordering scheme is relied on by the string-switching feature. Code in Druntime's core.internal.switch_ relies on this ordering when doing a binary search among case statements.

Both StringExp should be of the same encoding.

Parameters

NameDescription
se2 String expression to compare this to

Returns

0 when this is equal to se2, a value greater than 0 if this should be considered greater than se2, and a value less than 0 if this is lesser than se2.

Authors

Walter Bright

License

Boost License 1.0