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

ruby-changes:8357

From: matz <ko1@a...>
Date: Wed, 22 Oct 2008 14:56:19 +0900 (JST)
Subject: [ruby-changes:8357] Ruby:r19885 (trunk): * string.c (rb_external_str_new_with_enc): no implicit strlen call.

matz	2008-10-22 14:55:22 +0900 (Wed, 22 Oct 2008)

  New Revision: 19885

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19885

  Log:
    * string.c (rb_external_str_new_with_enc): no implicit strlen call.
      [ruby-dev:36854]
    
    * string.c (rb_external_str_new_cstr): new function to create
      string from external NUL terminated C string.
    
    * string.c (rb_locale_str_new_cstr): ditto.
    
    * ext/readline/readline.c: now use rb_locale_str_new_cstr().
    
    * test/sdbm/test_sdbm.rb (TestSDBM#test_delete_with_block):
      deleted key to the block may be a copy of specified key.
    
    * test/dbm/test_dbm.rb (TestDBM#test_delete_with_block): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/ext/readline/readline.c
    trunk/include/ruby/intern.h
    trunk/string.c
    trunk/test/dbm/test_dbm.rb
    trunk/test/sdbm/test_sdbm.rb

Index: include/ruby/intern.h
===================================================================
--- include/ruby/intern.h	(revision 19884)
+++ include/ruby/intern.h	(revision 19885)
@@ -548,7 +548,9 @@
 VALUE rb_tainted_str_new(const char*, long);
 VALUE rb_tainted_str_new2(const char*);
 VALUE rb_external_str_new(const char*, long);
+VALUE rb_external_str_new_cstr(const char*);
 VALUE rb_locale_str_new(const char*, long);
+VALUE rb_locale_str_new_cstr(const char*);
 VALUE rb_str_buf_new(long);
 VALUE rb_str_buf_new_cstr(const char*);
 VALUE rb_str_buf_new2(const char*);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19884)
+++ ChangeLog	(revision 19885)
@@ -1,3 +1,20 @@
+Wed Oct 22 14:52:17 2008  Yukihiro Matsumoto  <matz@r...>
+
+	* string.c (rb_external_str_new_with_enc): no implicit strlen call.
+	  [ruby-dev:36854]
+	
+	* string.c (rb_external_str_new_cstr): new function to create
+	  string from external NUL terminated C string.
+
+	* string.c (rb_locale_str_new_cstr): ditto.
+
+	* ext/readline/readline.c: now use rb_locale_str_new_cstr().
+
+	* test/sdbm/test_sdbm.rb (TestSDBM#test_delete_with_block):
+	  deleted key to the block may be a copy of specified key.
+
+	* test/dbm/test_dbm.rb (TestDBM#test_delete_with_block): ditto.
+
 Wed Oct 22 13:16:47 2008  Yukihiro Matsumoto  <matz@r...>
 
 	* re.c (unescape_escaped_nonascii): back out the last change on
Index: string.c
===================================================================
--- string.c	(revision 19884)
+++ string.c	(revision 19885)
@@ -529,7 +529,6 @@
 {
     VALUE str;
 
-    if (len == 0 && ptr) len = strlen(ptr);
     str = rb_tainted_str_new(ptr, len);
     rb_enc_associate(str, eenc);
     return rb_str_conv_enc(str, eenc, rb_default_internal_encoding());
@@ -542,12 +541,24 @@
 }
 
 VALUE
+rb_external_str_new_cstr(const char *ptr)
+{
+    return rb_external_str_new_with_enc(ptr, strlen(ptr), rb_default_external_encoding());
+}
+
+VALUE
 rb_locale_str_new(const char *ptr, long len)
 {
     return rb_external_str_new_with_enc(ptr, len, rb_locale_encoding());
 }
 
 VALUE
+rb_locale_str_new_cstr(const char *ptr)
+{
+    return rb_external_str_new_with_enc(ptr, strlen(ptr), rb_locale_encoding());
+}
+
+VALUE
 rb_str_export(VALUE str)
 {
     return rb_str_conv_enc(str, STR_ENC_GET(str), rb_default_external_encoding());
Index: ext/readline/readline.c
===================================================================
--- ext/readline/readline.c	(revision 19884)
+++ ext/readline/readline.c	(revision 19885)
@@ -246,7 +246,7 @@
 	add_history(buff);
     }
     if (buff) {
-	result = rb_locale_str_new(buff, strlen(buff));
+	result = rb_locale_str_new_cstr(buff);
     }
     else
 	result = Qnil;
@@ -385,7 +385,7 @@
     rl_attempted_completion_over = 1;
 #endif
     case_fold = RTEST(rb_attr_get(mReadline, completion_case_fold));
-    ary = rb_funcall(proc, rb_intern("call"), 1, rb_locale_str_new(text, strlen(text)));
+    ary = rb_funcall(proc, rb_intern("call"), 1, rb_locale_str_new_cstr(text));
     if (TYPE(ary) != T_ARRAY)
 	ary = rb_Array(ary);
     matches = RARRAY_LEN(ary);
@@ -608,7 +608,7 @@
     if (rl_completion_append_character == '\0')
 	return Qnil;
 
-    str = rb_str_new("", 1);
+    str = rb_str_new(0, 1);
     RSTRING_PTR(str)[0] = rl_completion_append_character;
     return str;
 #else
@@ -673,7 +673,7 @@
     rb_secure(4);
     if (rl_basic_word_break_characters == NULL)
 	return Qnil;
-    return rb_locale_str_new(rl_basic_word_break_characters, 0);
+    return rb_locale_str_new_cstr(rl_basic_word_break_characters);
 #else
     rb_notimplement();
     return Qnil; /* not reached */
@@ -736,7 +736,7 @@
     rb_secure(4);
     if (rl_completer_word_break_characters == NULL)
 	return Qnil;
-    return rb_locale_str_new(rl_completer_word_break_characters, 0);
+    return rb_locale_str_new_cstr(rl_completer_word_break_characters);
 #else
     rb_notimplement();
     return Qnil; /* not reached */
@@ -797,7 +797,7 @@
     rb_secure(4);
     if (rl_basic_quote_characters == NULL)
 	return Qnil;
-    return rb_locale_str_new(rl_basic_quote_characters, 0);
+    return rb_locale_str_new_cstr(rl_basic_quote_characters);
 #else
     rb_notimplement();
     return Qnil; /* not reached */
@@ -861,7 +861,7 @@
     rb_secure(4);
     if (rl_completer_quote_characters == NULL)
 	return Qnil;
-    return rb_locale_str_new(rl_completer_quote_characters, 0);
+    return rb_locale_str_new_cstr(rl_completer_quote_characters);
 #else
     rb_notimplement();
     return Qnil; /* not reached */
@@ -923,7 +923,7 @@
     rb_secure(4);
     if (rl_filename_quote_characters == NULL)
 	return Qnil;
-    return rb_locale_str_new(rl_filename_quote_characters, 0);
+    return rb_locale_str_new_cstr(rl_filename_quote_characters);
 #else
     rb_notimplement();
     return Qnil; /* not reached */
@@ -933,7 +933,7 @@
 static VALUE
 hist_to_s(VALUE self)
 {
-    return rb_str_new2("HISTORY");
+    return rb_str_new_cstr("HISTORY");
 }
 
 static int
@@ -965,7 +965,7 @@
     if (entry == NULL) {
 	rb_raise(rb_eIndexError, "invalid index");
     }
-    return rb_locale_str_new(entry->line, 0);
+    return rb_locale_str_new_cstr(entry->line);
 }
 
 static VALUE
@@ -1027,7 +1027,7 @@
     rb_secure(4);
     entry = remove_history(index);
     if (entry) {
-        val = rb_locale_str_new(entry->line, 0);
+        val = rb_locale_str_new_cstr(entry->line);
         free((void *) entry->line);
         free(entry);
         return val;
@@ -1074,7 +1074,7 @@
         entry = history_get(history_get_offset_func(i));
         if (entry == NULL)
             break;
-	rb_yield(rb_locale_str_new(entry->line, 0));
+	rb_yield(rb_locale_str_new_cstr(entry->line));
     }
     return self;
 }
@@ -1133,7 +1133,7 @@
     if (matches) {
 	result = rb_ary_new();
 	for (i = 0; matches[i]; i++) {
-	    rb_ary_push(result, rb_locale_str_new(matches[i], 0));
+	    rb_ary_push(result, rb_locale_str_new_cstr(matches[i]));
 	    free(matches[i]);
 	}
 	free(matches);
@@ -1158,7 +1158,7 @@
     if (matches) {
 	result = rb_ary_new();
 	for (i = 0; matches[i]; i++) {
-	    rb_ary_push(result, rb_locale_str_new(matches[i], 0));
+	    rb_ary_push(result, rb_locale_str_new_cstr(matches[i]));
 	    free(matches[i]);
 	}
 	free(matches);
@@ -1275,7 +1275,7 @@
     rb_define_const(mReadline, "USERNAME_COMPLETION_PROC", ucomp);
     history_get_offset_func = history_get_offset_history_base;
 #if defined HAVE_RL_LIBRARY_VERSION
-    version = rb_str_new2(rl_library_version);
+    version = rb_str_new_cstr(rl_library_version);
 #if defined HAVE_CLEAR_HISTORY || defined HAVE_REMOVE_HISTORY
     if (strncmp(rl_library_version, EDIT_LINE_LIBRARY_VERSION, 
 		strlen(EDIT_LINE_LIBRARY_VERSION)) == 0) {
@@ -1295,7 +1295,7 @@
     }
 #endif
 #else
-    version = rb_str_new2("2.0 or prior version");
+    version = rb_str_new_cstr("2.0 or prior version");
 #endif
     /* Version string of GNU Readline or libedit. */
     rb_define_const(mReadline, "VERSION", version);
Index: test/sdbm/test_sdbm.rb
===================================================================
--- test/sdbm/test_sdbm.rb	(revision 19884)
+++ test/sdbm/test_sdbm.rb	(revision 19885)
@@ -365,14 +365,11 @@
   def test_delete_with_block
     key = 'no called block'
     @sdbm[key] = 'foo'
-    assert_equal('foo', @sdbm.delete(key) {|k| k.replace 'called block'})
-    assert_equal('no called block', key)
+    assert_equal('foo', @sdbm.delete(key) {|k| k.replace 'called block'; :blockval})
     assert_equal(0, @sdbm.size)
 
     key = 'no called block'
-    assert_equal(:blockval,
-		  @sdbm.delete(key) {|k| k.replace 'called block'; :blockval})
-    assert_equal('called block', key)
+    assert_equal(:blockval, @sdbm.delete(key) {|k| k.replace 'called block'; :blockval})
     assert_equal(0, @sdbm.size)
   end
 
Index: test/dbm/test_dbm.rb
===================================================================
--- test/dbm/test_dbm.rb	(revision 19884)
+++ test/dbm/test_dbm.rb	(revision 19885)
@@ -334,14 +334,11 @@
     def test_delete_with_block
       key = 'no called block'
       @dbm[key] = 'foo'
-      assert_equal('foo', @dbm.delete(key) {|k| k.replace 'called block'})
-      assert_equal('no called block', key)
+      assert_equal('foo', @dbm.delete(key) {|k| k.replace 'called block'; :blockval})
       assert_equal(0, @dbm.size)
 
       key = 'no called block'
-      assert_equal(:blockval,
-                    @dbm.delete(key) {|k| k.replace 'called block'; :blockval})
-      assert_equal('called block', key)
+      assert_equal(:blockval, @dbm.delete(key) {|k| k.replace 'called block'; :blockval})
       assert_equal(0, @dbm.size)
     end
 

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

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