summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-05 01:29:12 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-05 01:29:12 +0000
commit3dc758d96601532e4ff27ab002cb558be7631396 (patch)
treea4171c2dc7c39829276047f15e97e3a382e2865b /string.c
parent37dd754e970cc177761093980cc249328866578a (diff)
* string.c (str_eql): extracted from rb_str_equal and rb_str_eql.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22775 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/string.c b/string.c
index e94f563995..d464d5f562 100644
--- a/string.c
+++ b/string.c
@@ -2227,7 +2227,18 @@ rb_str_cmp(VALUE str1, VALUE str2)
return -1;
}
+/* expect tail call optimization */
+static VALUE
+str_eql(const VALUE str1, const VALUE str2)
+{
+ const long len = RSTRING_LEN(str1);
+ if (len != RSTRING_LEN(str2)) return Qfalse;
+ if (!rb_str_comparable(str1, str2)) return Qfalse;
+ if (memcmp(RSTRING_PTR(str1), RSTRING_PTR(str2), len) == 0)
+ return Qtrue;
+ return Qfalse;
+}
/*
* call-seq:
* str == obj => true or false
@@ -2240,8 +2251,6 @@ rb_str_cmp(VALUE str1, VALUE str2)
VALUE
rb_str_equal(VALUE str1, VALUE str2)
{
- int len;
-
if (str1 == str2) return Qtrue;
if (TYPE(str2) != T_STRING) {
if (!rb_respond_to(str2, rb_intern("to_str"))) {
@@ -2249,12 +2258,7 @@ rb_str_equal(VALUE str1, VALUE str2)
}
return rb_equal(str2, str1);
}
- if (!rb_str_comparable(str1, str2)) return Qfalse;
- if (RSTRING_LEN(str1) == (len = RSTRING_LEN(str2)) &&
- memcmp(RSTRING_PTR(str1), RSTRING_PTR(str2), len) == 0) {
- return Qtrue;
- }
- return Qfalse;
+ return str_eql(str1, str2);
}
/*
@@ -2267,15 +2271,8 @@ rb_str_equal(VALUE str1, VALUE str2)
static VALUE
rb_str_eql(VALUE str1, VALUE str2)
{
- if (TYPE(str2) != T_STRING || RSTRING_LEN(str1) != RSTRING_LEN(str2))
- return Qfalse;
-
- if (!rb_str_comparable(str1, str2)) return Qfalse;
- if (memcmp(RSTRING_PTR(str1), RSTRING_PTR(str2),
- lesser(RSTRING_LEN(str1), RSTRING_LEN(str2))) == 0)
- return Qtrue;
-
- return Qfalse;
+ if (TYPE(str2) != T_STRING) return Qfalse;
+ return str_eql(str1, str2);
}
/*