go-strcmp.c 510 B

1234567891011121314151617181920212223242526
  1. /* go-strcmp.c -- the go string comparison function.
  2. Copyright 2009 The Go Authors. All rights reserved.
  3. Use of this source code is governed by a BSD-style
  4. license that can be found in the LICENSE file. */
  5. #include "runtime.h"
  6. intgo
  7. __go_strcmp(String s1, String s2)
  8. {
  9. int i;
  10. i = __builtin_memcmp(s1.str, s2.str,
  11. (s1.len < s2.len ? s1.len : s2.len));
  12. if (i != 0)
  13. return i;
  14. if (s1.len < s2.len)
  15. return -1;
  16. else if (s1.len > s2.len)
  17. return 1;
  18. else
  19. return 0;
  20. }