dir.c: reduce string object
* dir.c (dir_each): get rid of allocate new string from UTF-8 string. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42737 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
07bf69b085
commit
378161fe68
7
dir.c
7
dir.c
@ -627,14 +627,13 @@ dir_each(VALUE dir)
|
|||||||
size_t namlen = NAMLEN(dp);
|
size_t namlen = NAMLEN(dp);
|
||||||
VALUE path;
|
VALUE path;
|
||||||
#if HAVE_HFS
|
#if HAVE_HFS
|
||||||
VALUE utf8str = Qnil;
|
|
||||||
if (hfs_p && has_nonascii(name, namlen) &&
|
if (hfs_p && has_nonascii(name, namlen) &&
|
||||||
!NIL_P(utf8str = rb_str_normalize_ospath(name, namlen))) {
|
!NIL_P(path = rb_str_normalize_ospath(name, namlen))) {
|
||||||
RSTRING_GETMEM(utf8str, name, namlen);
|
path = rb_external_str_with_enc(path, dirp->enc);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
path = rb_external_str_new_with_enc(name, namlen, dirp->enc);
|
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);
|
rb_yield(path);
|
||||||
if (dirp->dir == NULL) dir_closed();
|
if (dirp->dir == NULL) dir_closed();
|
||||||
}
|
}
|
||||||
|
@ -434,6 +434,9 @@ VALUE rb_id_quote_unprintable(ID);
|
|||||||
#define QUOTE_ID(id) rb_id_quote_unprintable(id)
|
#define QUOTE_ID(id) rb_id_quote_unprintable(id)
|
||||||
void rb_str_fill_terminator(VALUE str, const int termlen);
|
void rb_str_fill_terminator(VALUE str, const int termlen);
|
||||||
VALUE rb_str_locktmp_ensure(VALUE str, VALUE (*func)(VALUE), VALUE arg);
|
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 */
|
/* struct.c */
|
||||||
VALUE rb_struct_init_copy(VALUE copy, VALUE s);
|
VALUE rb_struct_init_copy(VALUE copy, VALUE s);
|
||||||
|
6
string.c
6
string.c
@ -576,6 +576,12 @@ rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *eenc)
|
|||||||
VALUE str;
|
VALUE str;
|
||||||
|
|
||||||
str = rb_tainted_str_new(ptr, len);
|
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() &&
|
if (eenc == rb_usascii_encoding() &&
|
||||||
rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) {
|
rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) {
|
||||||
rb_enc_associate(str, rb_ascii8bit_encoding());
|
rb_enc_associate(str, rb_ascii8bit_encoding());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user