Skip to content

Commit

Permalink
* ruby.h (struct RString): embed small strings.
Browse files Browse the repository at this point in the history
  (RSTRING_LEN): defined for accessing string members.
  (RSTRING_PTR): ditto.

* string.c: use RSTRING_LEN and RSTRING_PTR.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10810 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Aug 31, 2006
1 parent 25c50cd commit 54af808
Show file tree
Hide file tree
Showing 23 changed files with 900 additions and 788 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Thu Aug 31 18:23:00 2006 Yukihiro Matsumoto <[email protected]>

* ruby.h (struct RString): embed small strings.
(RSTRING_LEN): defined for accessing string members.
(RSTRING_PTR): ditto.

* string.c: use RSTRING_LEN and RSTRING_PTR.

Thu Aug 31 17:16:19 2006 Yukihiro Matsumoto <[email protected]>

* array.c (rb_ary_shuffle_bang): new method.
Expand Down
12 changes: 6 additions & 6 deletions bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,10 @@ rb_str_to_inum(VALUE str, int base, int badcheck)
s = StringValueCStr(str);
}
else {
s = RSTRING(str)->ptr;
s = RSTRING_PTR(str);
}
if (s) {
len = RSTRING(str)->len;
len = RSTRING_LEN(str);
if (s[len]) { /* no sentinel somehow */
char *p = ALLOCA_N(char, len+1);

Expand Down Expand Up @@ -631,7 +631,7 @@ rb_big2str(VALUE x, int base)
t = rb_big_clone(x);
ds = BDIGITS(t);
ss = rb_str_new(0, j);
s = RSTRING(ss)->ptr;
s = RSTRING_PTR(ss);

s[0] = RBIGNUM(x)->sign ? '+' : '-';
while (i && j) {
Expand All @@ -653,9 +653,9 @@ rb_big2str(VALUE x, int base)
}
}
while (s[j] == '0') j++;
RSTRING(ss)->len -= RBIGNUM(x)->sign?j:j-1;
memmove(RBIGNUM(x)->sign?s:s+1, s+j, RSTRING(ss)->len);
s[RSTRING(ss)->len] = '\0';
i = RSTRING_LEN(ss)-(RBIGNUM(x)->sign?j:j-1);
memmove(RBIGNUM(x)->sign?s:s+1, s+j, i);
rb_str_set_len(ss, i);

return ss;
}
Expand Down
44 changes: 22 additions & 22 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,17 +394,17 @@ dir_initialize(VALUE dir, VALUE dirname)
if (dp->path) free(dp->path);
dp->dir = NULL;
dp->path = NULL;
dp->dir = opendir(RSTRING(dirname)->ptr);
dp->dir = opendir(RSTRING_PTR(dirname));
if (dp->dir == NULL) {
if (errno == EMFILE || errno == ENFILE) {
rb_gc();
dp->dir = opendir(RSTRING(dirname)->ptr);
dp->dir = opendir(RSTRING_PTR(dirname));
}
if (dp->dir == NULL) {
rb_sys_fail(RSTRING(dirname)->ptr);
rb_sys_fail(RSTRING_PTR(dirname));
}
}
dp->path = strdup(RSTRING(dirname)->ptr);
dp->path = strdup(RSTRING_PTR(dirname));

return dir;
}
Expand Down Expand Up @@ -470,7 +470,7 @@ dir_inspect(VALUE dir)
char *c = rb_obj_classname(dir);
int len = strlen(c) + strlen(dirp->path) + 4;
VALUE s = rb_str_new(0, len);
snprintf(RSTRING(s)->ptr, len+1, "#<%s:%s>", c, dirp->path);
snprintf(RSTRING_PTR(s), len+1, "#<%s:%s>", c, dirp->path);
return s;
}
return rb_funcall(dir, rb_intern("to_s"), 0, 0);
Expand Down Expand Up @@ -688,8 +688,8 @@ dir_close(VALUE dir)
static void
dir_chdir(VALUE path)
{
if (chdir(RSTRING(path)->ptr) < 0)
rb_sys_fail(RSTRING(path)->ptr);
if (chdir(RSTRING_PTR(path)) < 0)
rb_sys_fail(RSTRING_PTR(path));
}

static int chdir_blocking = 0;
Expand Down Expand Up @@ -831,7 +831,7 @@ check_dirname(volatile VALUE *dir)

rb_secure(2);
FilePathValue(*dir);
path = RSTRING(*dir)->ptr;
path = RSTRING_PTR(*dir);
if (path && *(pend = rb_path_end(rb_path_skip_prefix(path)))) {
*dir = rb_str_new(path, pend - path);
}
Expand All @@ -852,8 +852,8 @@ dir_s_chroot(VALUE dir, VALUE path)
#if defined(HAVE_CHROOT) && !defined(__CHECKER__)
check_dirname(&path);

if (chroot(RSTRING(path)->ptr) == -1)
rb_sys_fail(RSTRING(path)->ptr);
if (chroot(RSTRING_PTR(path)) == -1)
rb_sys_fail(RSTRING_PTR(path));

return INT2FIX(0);
#else
Expand Down Expand Up @@ -889,8 +889,8 @@ dir_s_mkdir(int argc, VALUE *argv, VALUE obj)
}

check_dirname(&path);
if (mkdir(RSTRING(path)->ptr, mode) == -1)
rb_sys_fail(RSTRING(path)->ptr);
if (mkdir(RSTRING_PTR(path), mode) == -1)
rb_sys_fail(RSTRING_PTR(path));

return INT2FIX(0);
}
Expand All @@ -908,8 +908,8 @@ static VALUE
dir_s_rmdir(VALUE obj, VALUE dir)
{
check_dirname(&dir);
if (rmdir(RSTRING(dir)->ptr) < 0)
rb_sys_fail(RSTRING(dir)->ptr);
if (rmdir(RSTRING_PTR(dir)) < 0)
rb_sys_fail(RSTRING_PTR(dir));

return INT2FIX(0);
}
Expand Down Expand Up @@ -1501,17 +1501,17 @@ rb_push_glob(VALUE str, int flags) /* '\0' is delimiter */

ary = rb_ary_new();

while (offset < RSTRING(str)->len) {
int status = push_glob(ary, RSTRING(str)->ptr + offset, flags);
while (offset < RSTRING_LEN(str)) {
int status = push_glob(ary, RSTRING_PTR(str) + offset, flags);
char *p, *pend;
if (status) rb_jump_tag(status);
if (offset >= RSTRING(str)->len) break;
p = RSTRING(str)->ptr + offset;
if (offset >= RSTRING_LEN(str)) break;
p = RSTRING_PTR(str) + offset;
p += strlen(p) + 1;
pend = RSTRING(str)->ptr + RSTRING(str)->len;
pend = RSTRING_PTR(str) + RSTRING_LEN(str);
while (p < pend && !*p)
p++;
offset = p - RSTRING(str)->ptr;
offset = p - RSTRING_PTR(str);
}

return ary;
Expand All @@ -1527,7 +1527,7 @@ dir_globs(long argc, VALUE *argv, int flags)
int status;
VALUE str = argv[i];
FilePathValue(str);
status = push_glob(ary, RSTRING(str)->ptr, flags);
status = push_glob(ary, RSTRING_PTR(str), flags);
if (status) rb_jump_tag(status);
}

Expand Down Expand Up @@ -1797,7 +1797,7 @@ file_s_fnmatch(int argc, VALUE *argv, VALUE obj)
StringValue(pattern);
StringValue(path);

if (fnmatch(RSTRING(pattern)->ptr, RSTRING(path)->ptr, flags) == 0)
if (fnmatch(RSTRING_PTR(pattern), RSTRING_PTR(path), flags) == 0)
return Qtrue;

return Qfalse;
Expand Down
12 changes: 6 additions & 6 deletions error.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ rb_check_type(VALUE x, int t)
etype = "Symbol";
}
else if (rb_special_const_p(x)) {
etype = RSTRING(rb_obj_as_string(x))->ptr;
etype = RSTRING_PTR(rb_obj_as_string(x));
}
else {
etype = rb_obj_classname(x);
Expand Down Expand Up @@ -378,7 +378,7 @@ exc_inspect(VALUE exc)

klass = CLASS_OF(exc);
exc = rb_obj_as_string(exc);
if (RSTRING(exc)->len == 0) {
if (RSTRING_LEN(exc) == 0) {
return rb_str_dup(rb_class_name(klass));
}

Expand Down Expand Up @@ -699,10 +699,10 @@ name_err_mesg_to_str(VALUE obj)
break;
default:
d = rb_protect(rb_inspect, obj, 0);
if (NIL_P(d) || RSTRING(d)->len > 65) {
if (NIL_P(d) || RSTRING_LEN(d) > 65) {
d = rb_any_to_s(obj);
}
desc = RSTRING(d)->ptr;
desc = RSTRING_PTR(d);
break;
}
if (desc && desc[0] != '#') {
Expand Down Expand Up @@ -745,7 +745,7 @@ rb_invalid_str(const char *str, const char *type)
{
VALUE s = rb_str_inspect(rb_str_new2(str));

rb_raise(rb_eArgError, "invalid value for %s: %s", type, RSTRING(s)->ptr);
rb_raise(rb_eArgError, "invalid value for %s: %s", type, RSTRING_PTR(s));
}

/*
Expand Down Expand Up @@ -856,7 +856,7 @@ syserr_initialize(int argc, VALUE *argv, VALUE self)

StringValue(str);
mesg = rb_sprintf("%s - %.*s", err,
(int)RSTRING(str)->len, RSTRING(str)->ptr);
(int)RSTRING_LEN(str), RSTRING_PTR(str));
}
else {
mesg = rb_str_new2(err);
Expand Down
Loading

0 comments on commit 54af808

Please sign in to comment.