Skip to content

Instantly share code, notes, and snippets.

@tyler-smith
Created December 19, 2012 23:49
Show Gist options
  • Save tyler-smith/4341815 to your computer and use it in GitHub Desktop.
Save tyler-smith/4341815 to your computer and use it in GitHub Desktop.
int
rb_str_cmp(VALUE str1, VALUE str2)
{
long len1, len2;
const char *ptr1, *ptr2;
int retval;
if (str1 == str2) return 0;
RSTRING_GETMEM(str1, ptr1, len1);
RSTRING_GETMEM(str2, ptr2, len2);
if (ptr1 == ptr2 || (retval = memcmp(ptr1, ptr2, lesser(len1, len2))) == 0) {
if (len1 == len2) {
if (!rb_str_comparable(str1, str2)) {
if (ENCODING_GET(str1) > ENCODING_GET(str2))
return 1;
return -1;
}
return 0;
}
if (len1 > len2) return 1;
return -1;
}
if (retval > 0) return 1;
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment