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

ruby-changes:30657

From: nobu <ko1@a...>
Date: Sat, 31 Aug 2013 13:30:41 +0900 (JST)
Subject: [ruby-changes:30657] nobu:r42737 (trunk): dir.c: reduce string object

nobu	2013-08-31 13:30:25 +0900 (Sat, 31 Aug 2013)

  New Revision: 42737

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

  Log:
    dir.c: reduce string object
    
    * dir.c (dir_each): get rid of allocate new string from UTF-8 string.

  Modified files:
    trunk/dir.c
    trunk/internal.h
    trunk/string.c
Index: string.c
===================================================================
--- string.c	(revision 42736)
+++ string.c	(revision 42737)
@@ -576,6 +576,12 @@ rb_external_str_new_with_enc(const char https://github.com/ruby/ruby/blob/trunk/string.c#L576
     VALUE str;
 
     str = rb_tainted_str_new(ptr, len);
+    return rb_external_str_with_enc(str, eenc);
+}
+
+VALUE
+rb_external_str_with_enc(VALUE str, rb_encoding *eenc)
+{
     if (eenc == rb_usascii_encoding() &&
 	rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) {
 	rb_enc_associate(str, rb_ascii8bit_encoding());
Index: dir.c
===================================================================
--- dir.c	(revision 42736)
+++ dir.c	(revision 42737)
@@ -627,14 +627,13 @@ dir_each(VALUE dir) https://github.com/ruby/ruby/blob/trunk/dir.c#L627
 	size_t namlen = NAMLEN(dp);
 	VALUE path;
 #if HAVE_HFS
-	VALUE utf8str = Qnil;
 	if (hfs_p && has_nonascii(name, namlen) &&
-	    !NIL_P(utf8str = rb_str_normalize_ospath(name, namlen))) {
-	    RSTRING_GETMEM(utf8str, name, namlen);
+	    !NIL_P(path = rb_str_normalize_ospath(name, namlen))) {
+	    path = rb_external_str_with_enc(path, dirp->enc);
 	}
+	else
 #endif
 	path = rb_external_str_new_with_enc(name, namlen, dirp->enc);
-	IF_HAVE_HFS(if (!NIL_P(utf8str)) rb_str_resize(utf8str, 0));
 	rb_yield(path);
 	if (dirp->dir == NULL) dir_closed();
     }
Index: internal.h
===================================================================
--- internal.h	(revision 42736)
+++ internal.h	(revision 42737)
@@ -434,6 +434,9 @@ VALUE rb_id_quote_unprintable(ID); https://github.com/ruby/ruby/blob/trunk/internal.h#L434
 #define QUOTE_ID(id) rb_id_quote_unprintable(id)
 void rb_str_fill_terminator(VALUE str, const int termlen);
 VALUE rb_str_locktmp_ensure(VALUE str, VALUE (*func)(VALUE), VALUE arg);
+#ifdef RUBY_ENCODING_H
+VALUE rb_external_str_with_enc(VALUE str, rb_encoding *eenc);
+#endif
 
 /* struct.c */
 VALUE rb_struct_init_copy(VALUE copy, VALUE s);

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

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