[前][次][番号順一覧][スレッド一覧]

ruby-changes:3951

From: ko1@a...
Date: Tue, 12 Feb 2008 12:18:02 +0900 (JST)
Subject: [ruby-changes:3951] matz - Ruby:r15441 (trunk): * string.c (rb_str_hash_cmp): lighter version of rb_str_cmp() for

matz	2008-02-12 12:17:43 +0900 (Tue, 12 Feb 2008)

  New Revision: 15441

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
    trunk/include/ruby/intern.h
    trunk/parse.y
    trunk/string.c

  Log:
    * string.c (rb_str_hash_cmp): lighter version of rb_str_cmp() for
      hash comparison function.
    
    * hash.c (rb_any_cmp): use rb_str_hash_cmp().
    
    * string.c (rb_str_casecmp): should return nil for incompatible
      comparison.

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/string.c?r1=15441&r2=15440&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/hash.c?r1=15441&r2=15440&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/parse.y?r1=15441&r2=15440&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15441&r2=15440&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/include/ruby/intern.h?r1=15441&r2=15440&diff_format=u

Index: include/ruby/intern.h
===================================================================
--- include/ruby/intern.h	(revision 15440)
+++ include/ruby/intern.h	(revision 15441)
@@ -528,6 +528,7 @@
 VALUE rb_str_concat(VALUE, VALUE);
 int rb_memhash(const void *ptr, long len);
 int rb_str_hash(VALUE);
+int rb_str_hash_cmp(VALUE,VALUE);
 int rb_str_comparable(VALUE, VALUE);
 int rb_str_cmp(VALUE, VALUE);
 VALUE rb_str_equal(VALUE str1, VALUE str2);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 15440)
+++ ChangeLog	(revision 15441)
@@ -1,3 +1,13 @@
+Tue Feb 12 12:16:45 2008  Yukihiro Matsumoto  <matz@r...>
+
+	* string.c (rb_str_hash_cmp): lighter version of rb_str_cmp() for
+	  hash comparison function.
+
+	* hash.c (rb_any_cmp): use rb_str_hash_cmp().
+
+	* string.c (rb_str_casecmp): should return nil for incompatible
+	  comparison.
+
 Tue Feb 12 12:13:25 2008  Yukihiro Matsumoto  <matz@r...>
 
 	* instruby.rb: specify file mode to install.  a patch from
Index: string.c
===================================================================
--- string.c	(revision 15440)
+++ string.c	(revision 15441)
@@ -1512,6 +1512,19 @@
     return hash((const void *)RSTRING_PTR(str), RSTRING_LEN(str), 0);
 }
 
+int
+rb_str_hash_cmp(VALUE str1, VALUE str2)
+{
+    int len;
+
+    if (!rb_str_comparable(str1, str2)) return 1;
+    if (RSTRING_LEN(str1) == (len = RSTRING_LEN(str2)) &&
+	memcmp(RSTRING_PTR(str1), RSTRING_PTR(str2), len) == 0) {
+	return 0;
+    }
+    return 1;
+}
+
 /*
  * call-seq:
  *    str.hash   => fixnum
@@ -1700,7 +1713,7 @@
     StringValue(str2);
     enc = rb_enc_compatible(str1, str2);
     if (!enc) {
-	return rb_str_cmp(str1, str2);
+	return Qnil;
     }
 
     p1 = RSTRING_PTR(str1); p1end = RSTRING_END(str1);
Index: parse.y
===================================================================
--- parse.y	(revision 15440)
+++ parse.y	(revision 15441)
@@ -8749,7 +8749,7 @@
 } global_symbols = {tLAST_TOKEN >> ID_SCOPE_SHIFT};
 
 static const struct st_hash_type symhash = {
-    rb_str_cmp,
+    rb_str_hash_cmp,
     rb_str_hash,
 };
 
Index: hash.c
===================================================================
--- hash.c	(revision 15440)
+++ hash.c	(revision 15441)
@@ -53,7 +53,7 @@
     }
     if (TYPE(a) == T_STRING && RBASIC(a)->klass == rb_cString &&
 	TYPE(b) == T_STRING && RBASIC(b)->klass == rb_cString) {
-	return rb_str_cmp(a, b);
+	return rb_str_hash_cmp(a, b);
     }
     if (a == Qundef || b == Qundef) return -1;
     if (SYMBOL_P(a) && SYMBOL_P(b)) {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]