1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* include/ruby/intern.h (rb_str_new2, rb_tainted_str_new2,

rb_usascii_str_new2): use with-length versions with strlen to
  optimize strlen, if optimized.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2008-08-12 09:56:55 +00:00
parent 741cc67800
commit 456dc8bcee
3 changed files with 76 additions and 30 deletions

View file

@ -1,3 +1,9 @@
Tue Aug 12 18:56:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* include/ruby/intern.h (rb_str_new2, rb_tainted_str_new2,
rb_usascii_str_new2): use with-length versions with strlen to
optimize strlen, if optimized.
Tue Aug 12 18:51:29 2008 TAKAO Kouji <kouji@takao7.net>
* gc.c (getrusage_time): Returned effective value on Windows.

View file

@ -530,16 +530,23 @@ VALUE rb_str_vcatf(VALUE, const char*, va_list);
VALUE rb_str_format(int, const VALUE *, VALUE);
/* string.c */
VALUE rb_str_new(const char*, long);
VALUE rb_str_new_cstr(const char*);
VALUE rb_str_new2(const char*);
VALUE rb_str_new_shared(VALUE);
VALUE rb_str_new3(VALUE);
VALUE rb_str_new_frozen(VALUE);
VALUE rb_str_new4(VALUE);
VALUE rb_str_new_with_class(VALUE, const char*, long);
VALUE rb_str_new5(VALUE, const char*, long);
VALUE rb_tainted_str_new_cstr(const char*);
VALUE rb_tainted_str_new(const char*, long);
VALUE rb_tainted_str_new2(const char*);
VALUE rb_str_buf_new(long);
VALUE rb_str_buf_new_cstr(const char*);
VALUE rb_str_buf_new2(const char*);
VALUE rb_str_tmp_new(long);
VALUE rb_usascii_str_new(const char*, long);
VALUE rb_usascii_str_new_cstr(const char*);
VALUE rb_usascii_str_new2(const char*);
void rb_str_free(VALUE);
void rb_str_shared_replace(VALUE, VALUE);
@ -553,6 +560,7 @@ VALUE rb_str_dup(VALUE);
VALUE rb_str_locktmp(VALUE);
VALUE rb_str_unlocktmp(VALUE);
VALUE rb_str_dup_frozen(VALUE);
#define rb_str_dup_frozen rb_str_new_frozen
VALUE rb_str_plus(VALUE, VALUE);
VALUE rb_str_times(VALUE, VALUE);
long rb_str_sublen(VALUE, long);
@ -584,30 +592,30 @@ VALUE rb_sym_to_s(VALUE);
VALUE rb_str_length(VALUE);
size_t rb_str_capacity(VALUE);
#if defined __GNUC__
#define rb_str_new2(str) __extension__ ( \
#define rb_str_new_cstr(str) __extension__ ( \
{ \
(__builtin_constant_p(str)) ? \
rb_str_new(str, strlen(str)) : \
rb_str_new2(str); \
rb_str_new_cstr(str); \
})
#define rb_tainted_str_new2(str) __extension__ ( \
#define rb_tainted_str_new_cstr(str) __extension__ ( \
{ \
(__builtin_constant_p(str)) ? \
rb_tainted_str_new(str, strlen(str)) : \
rb_tainted_str_new2(str); \
rb_tainted_str_new_cstr(str); \
})
#define rb_usascii_str_new2(str) __extension__ ( \
#define rb_usascii_str_new_cstr(str) __extension__ ( \
{ \
(__builtin_constant_p(str)) ? \
rb_usascii_str_new(str, strlen(str)) : \
rb_usascii_str_new2(str); \
rb_usascii_str_new_cstr(str); \
})
#define rb_str_buf_new2(str) __extension__ ( \
#define rb_str_buf_new_cstr(str) __extension__ ( \
{ \
(__builtin_constant_p(str)) ? \
rb_str_buf_cat(rb_str_buf_new(strlen(str)), \
str, strlen(str)) : \
rb_str_buf_new2(str); \
rb_str_buf_new_cstr(str); \
})
#define rb_str_buf_cat2(str, ptr) __extension__ ( \
{ \
@ -622,6 +630,13 @@ size_t rb_str_capacity(VALUE);
rb_str_cat2(str, ptr); \
})
#endif
#define rb_str_new2 rb_str_new_cstr
#define rb_str_new3 rb_str_new_shared
#define rb_str_new4 rb_str_new_frozen
#define rb_str_new5 rb_str_new_with_class
#define rb_tainted_str_new2 rb_tainted_str_new_cstr
#define rb_str_buf_new2 rb_str_buf_new_cstr
#define rb_usascii_str_new2 rb_usascii_str_new_cstr
/* struct.c */
VALUE rb_struct_new(VALUE, ...);
VALUE rb_struct_define(const char*, ...);

View file

@ -25,9 +25,17 @@
#include <unistd.h>
#endif
#undef rb_str_new_cstr
#undef rb_tainted_str_new_cstr
#undef rb_usascii_str_new_cstr
#undef rb_str_new2
#undef rb_str_new3
#undef rb_str_new4
#undef rb_str_new5
#undef rb_tainted_str_new2
#undef rb_usascii_str_new2
#undef rb_str_dup_frozen
#undef rb_str_buf_new_cstr
#undef rb_str_buf_new2
#undef rb_str_buf_cat2
#undef rb_str_cat2
@ -35,6 +43,14 @@
VALUE rb_cString;
VALUE rb_cSymbol;
#ifdef __GNUC__
#define alias_func(old_prot, new_name, args) \
VALUE old_prot __attribute__((alias(#new_name)));
#else
#define alias_func(old_prot, new_name, args) \
VALUE old_prot {return new_name args;}
#endif
#define STR_TMPLOCK FL_USER7
#define STR_NOEMBED FL_USER1
#define STR_SHARED FL_USER2 /* = ELTS_SHARED */
@ -416,7 +432,7 @@ rb_enc_str_new(const char *ptr, long len, rb_encoding *enc)
}
VALUE
rb_str_new2(const char *ptr)
rb_str_new_cstr(const char *ptr)
{
if (!ptr) {
rb_raise(rb_eArgError, "NULL pointer given");
@ -424,14 +440,20 @@ rb_str_new2(const char *ptr)
return rb_str_new(ptr, strlen(ptr));
}
alias_func(rb_str_new2(const char *ptr), rb_str_new_cstr, (ptr))
#define rb_str_new2 rb_str_new_cstr
VALUE
rb_usascii_str_new2(const char *ptr)
rb_usascii_str_new_cstr(const char *ptr)
{
VALUE str = rb_str_new2(ptr);
ENCODING_CODERANGE_SET(str, rb_usascii_encindex(), ENC_CODERANGE_7BIT);
return str;
}
alias_func(rb_usascii_str_new2(const char *ptr), rb_usascii_str_new_cstr, (ptr))
#define rb_usascii_str_new2 rb_usascii_str_new_cstr
VALUE
rb_tainted_str_new(const char *ptr, long len)
{
@ -442,7 +464,7 @@ rb_tainted_str_new(const char *ptr, long len)
}
VALUE
rb_tainted_str_new2(const char *ptr)
rb_tainted_str_new_cstr(const char *ptr)
{
VALUE str = rb_str_new2(ptr);
@ -450,6 +472,9 @@ rb_tainted_str_new2(const char *ptr)
return str;
}
alias_func(rb_tainted_str_new2(const char *ptr), rb_tainted_str_new_cstr, (ptr))
#define rb_tainted_str_new2 rb_tainted_str_new_cstr
static VALUE
str_replace_shared(VALUE str2, VALUE str)
{
@ -483,7 +508,7 @@ str_new3(VALUE klass, VALUE str)
}
VALUE
rb_str_new3(VALUE str)
rb_str_new_shared(VALUE str)
{
VALUE str2 = str_new3(rb_obj_class(str), str);
@ -491,6 +516,9 @@ rb_str_new3(VALUE str)
return str2;
}
alias_func(rb_str_new3(VALUE str), rb_str_new_shared, (str))
#define rb_str_new3 rb_str_new_shared
static VALUE
str_new4(VALUE klass, VALUE str)
{
@ -514,7 +542,7 @@ str_new4(VALUE klass, VALUE str)
}
VALUE
rb_str_new4(VALUE orig)
rb_str_new_frozen(VALUE orig)
{
VALUE klass, str;
@ -551,12 +579,19 @@ rb_str_new4(VALUE orig)
return str;
}
alias_func(rb_str_new4(VALUE orig), rb_str_new_frozen, (orig))
#define rb_str_new4 rb_str_new_frozen
VALUE
rb_str_new5(VALUE obj, const char *ptr, long len)
rb_str_new_with_class(VALUE obj, const char *ptr, long len)
{
return str_new(rb_obj_class(obj), ptr, len);
}
alias_func(rb_str_new5(VALUE obj, const char *ptr, long len),
rb_str_new_with_class, (obj, ptr, len))
#define rb_str_new5 rb_str_new_with_class
#define STR_BUF_MIN_SIZE 128
VALUE
@ -576,7 +611,7 @@ rb_str_buf_new(long capa)
}
VALUE
rb_str_buf_new2(const char *ptr)
rb_str_buf_new_cstr(const char *ptr)
{
VALUE str;
long len = strlen(ptr);
@ -587,6 +622,9 @@ rb_str_buf_new2(const char *ptr)
return str;
}
alias_func(rb_str_buf_new2(const char *ptr), rb_str_buf_new_cstr, (ptr))
#define rb_str_buf_new2 rb_str_buf_new_cstr
VALUE
rb_str_tmp_new(long len)
{
@ -1327,21 +1365,8 @@ rb_str_freeze(VALUE str)
return rb_obj_freeze(str);
}
VALUE
rb_str_dup_frozen(VALUE str)
{
if (STR_SHARED_P(str) && RSTRING(str)->as.heap.aux.shared) {
VALUE shared = RSTRING(str)->as.heap.aux.shared;
if (RSTRING_LEN(shared) == RSTRING_LEN(str)) {
OBJ_FREEZE(shared);
return shared;
}
}
if (OBJ_FROZEN(str)) return str;
str = rb_str_dup(str);
OBJ_FREEZE(str);
return str;
}
alias_func(rb_str_dup_frozen(VALUE str), rb_str_new_frozen, (str))
#define rb_str_dup_frozen rb_str_new_frozen
VALUE
rb_str_locktmp(VALUE str)