diff options
author | Mathias Stearn <redbeard0531@gmail.com> | 2017-12-24 09:23:17 -0500 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-12-24 15:23:17 +0100 |
commit | 6bd3a2826fb559d4e88cd2fa5ba89be995553700 (patch) | |
tree | 923cbbbc7451a729a1ccf0dcb89ba01a2d411281 /lib/system | |
parent | ca9f3b47d41c1a2a525df1b850194e28ac0da728 (diff) | |
download | Nim-6bd3a2826fb559d4e88cd2fa5ba89be995553700.tar.gz |
cmp(x, y: string) now uses memcmp rather than strcmp (#6869) (#6968)
Diffstat (limited to 'lib/system')
-rw-r--r-- | lib/system/sysstr.nim | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/system/sysstr.nim b/lib/system/sysstr.nim index 56b8ade97..4c5f3d9a1 100644 --- a/lib/system/sysstr.nim +++ b/lib/system/sysstr.nim @@ -24,10 +24,10 @@ proc cmpStrings(a, b: NimString): int {.inline, compilerProc.} = if a == b: return 0 if a == nil: return -1 if b == nil: return 1 - when defined(nimNoArrayToCstringConversion): - return c_strcmp(addr a.data, addr b.data) - else: - return c_strcmp(a.data, b.data) + let minlen = min(a.len, b.len) + result = c_memcmp(addr a.data, addr b.data, minlen.csize) + if result == 0: + result = a.len - b.len proc eqStrings(a, b: NimString): bool {.inline, compilerProc.} = if a == b: return true |