2010-12-03 05:34:57 +01:00
|
|
|
/* go-strcmp.c -- the go string comparison function.
|
|
|
|
|
|
|
|
Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
Use of this source code is governed by a BSD-style
|
|
|
|
license that can be found in the LICENSE file. */
|
|
|
|
|
2012-11-01 04:02:13 +01:00
|
|
|
#include "runtime.h"
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2012-11-01 04:02:13 +01:00
|
|
|
intgo
|
|
|
|
__go_strcmp(String s1, String s2)
|
2010-12-03 05:34:57 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-11-01 04:02:13 +01:00
|
|
|
i = __builtin_memcmp(s1.str, s2.str,
|
|
|
|
(s1.len < s2.len ? s1.len : s2.len));
|
2010-12-03 05:34:57 +01:00
|
|
|
if (i != 0)
|
|
|
|
return i;
|
|
|
|
|
2012-11-01 04:02:13 +01:00
|
|
|
if (s1.len < s2.len)
|
2010-12-03 05:34:57 +01:00
|
|
|
return -1;
|
2012-11-01 04:02:13 +01:00
|
|
|
else if (s1.len > s2.len)
|
2010-12-03 05:34:57 +01:00
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|