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@10809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Aug 31, 2006
1 parent 22f249e commit 25c50cd
Show file tree
Hide file tree
Showing 43 changed files with 484 additions and 512 deletions.
18 changes: 9 additions & 9 deletions ext/bigdecimal/bigdecimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,14 @@ GetVpValue(VALUE v, int must)
#ifdef ENABLE_NUMERIC_STRING
case T_STRING:
SafeStringValue(v);
return VpCreateRbObject(strlen(RSTRING(v)->ptr) + VpBaseFig() + 1,
RSTRING(v)->ptr);
return VpCreateRbObject(strlen(RSTRING_PTR(v)) + VpBaseFig() + 1,
RSTRING_PTR(v));
#endif /* ENABLE_NUMERIC_STRING */

case T_BIGNUM:
bg = rb_big2str(v, 10);
return VpCreateRbObject(strlen(RSTRING(bg)->ptr) + VpBaseFig() + 1,
RSTRING(bg)->ptr);
return VpCreateRbObject(strlen(RSTRING_PTR(bg)) + VpBaseFig() + 1,
RSTRING_PTR(bg));
default:
goto SomeOneMayDoIt;
}
Expand All @@ -240,7 +240,7 @@ GetVpValue(VALUE v, int must)
if(must) {
rb_raise(rb_eTypeError, "%s can't be coerced into BigDecimal",
rb_special_const_p(v)?
RSTRING(rb_inspect(v))->ptr:
RSTRING_PTR(rb_inspect(v)):
rb_obj_classname(v)
);
}
Expand Down Expand Up @@ -332,7 +332,7 @@ BigDecimal_load(VALUE self, VALUE str)
unsigned long m=0;

SafeStringValue(str);
pch = RSTRING(str)->ptr;
pch = RSTRING_PTR(str);
/* First get max prec */
while((*pch)!=(unsigned char)'\0' && (ch=*pch++)!=(unsigned char)':') {
if(!ISDIGIT(ch)) {
Expand Down Expand Up @@ -1510,7 +1510,7 @@ BigDecimal_to_s(int argc, VALUE *argv, VALUE self)
if(rb_scan_args(argc,argv,"01",&f)==1) {
if(TYPE(f)==T_STRING) {
SafeStringValue(f);
psz = RSTRING(f)->ptr;
psz = RSTRING_PTR(f);
if(*psz==' ') {
fPlus = 1; psz++;
} else if(*psz=='+') {
Expand Down Expand Up @@ -1687,7 +1687,7 @@ BigDecimal_global_new(int argc, VALUE *argv, VALUE self)
mf = GetPositiveInt(nFig);
}
SafeStringValue(iniValue);
GUARD_OBJ(pv,VpCreateRbObject(mf, RSTRING(iniValue)->ptr));
GUARD_OBJ(pv,VpCreateRbObject(mf, RSTRING_PTR(iniValue)));
return ToValue(pv);
}

Expand Down Expand Up @@ -1718,7 +1718,7 @@ BigDecimal_new(int argc, VALUE *argv, VALUE self)
mf = GetPositiveInt(nFig);
}
SafeStringValue(iniValue);
GUARD_OBJ(pv,VpNewRbClass(mf, RSTRING(iniValue)->ptr,self));
GUARD_OBJ(pv,VpNewRbClass(mf, RSTRING_PTR(iniValue),self));
return ToValue(pv);
}

Expand Down
50 changes: 25 additions & 25 deletions ext/dbm/dbm.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,24 @@ fdbm_initialize(int argc, VALUE *argv, VALUE obj)

if (flags & RUBY_DBM_RW_BIT) {
flags &= ~RUBY_DBM_RW_BIT;
dbm = dbm_open(RSTRING(file)->ptr, flags, mode);
dbm = dbm_open(RSTRING_PTR(file), flags, mode);
}
else {
dbm = 0;
if (mode >= 0) {
dbm = dbm_open(RSTRING(file)->ptr, O_RDWR|O_CREAT, mode);
dbm = dbm_open(RSTRING_PTR(file), O_RDWR|O_CREAT, mode);
}
if (!dbm) {
dbm = dbm_open(RSTRING(file)->ptr, O_RDWR, 0);
dbm = dbm_open(RSTRING_PTR(file), O_RDWR, 0);
}
if (!dbm) {
dbm = dbm_open(RSTRING(file)->ptr, O_RDONLY, 0);
dbm = dbm_open(RSTRING_PTR(file), O_RDONLY, 0);
}
}

if (!dbm) {
if (mode == -1) return Qnil;
rb_sys_fail(RSTRING(file)->ptr);
rb_sys_fail(RSTRING_PTR(file));
}

dbmp = ALLOC(struct dbmdata);
Expand Down Expand Up @@ -166,8 +166,8 @@ fdbm_fetch(VALUE obj, VALUE keystr, VALUE ifnone)
DBM *dbm;

StringValue(keystr);
key.dptr = RSTRING(keystr)->ptr;
key.dsize = RSTRING(keystr)->len;
key.dptr = RSTRING_PTR(keystr);
key.dsize = RSTRING_LEN(keystr);

GetDBM2(obj, dbmp, dbm);
value = dbm_fetch(dbm, key);
Expand Down Expand Up @@ -206,14 +206,14 @@ fdbm_index(VALUE obj, VALUE valstr)
DBM *dbm;

StringValue(valstr);
val.dptr = RSTRING(valstr)->ptr;
val.dsize = RSTRING(valstr)->len;
val.dptr = RSTRING_PTR(valstr);
val.dsize = RSTRING_LEN(valstr);

GetDBM2(obj, dbmp, dbm);
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
val = dbm_fetch(dbm, key);
if (val.dsize == RSTRING(valstr)->len &&
memcmp(val.dptr, RSTRING(valstr)->ptr, val.dsize) == 0) {
if (val.dsize == RSTRING_LEN(valstr) &&
memcmp(val.dptr, RSTRING_PTR(valstr), val.dsize) == 0) {
return rb_tainted_str_new(key.dptr, key.dsize);
}
}
Expand Down Expand Up @@ -274,8 +274,8 @@ fdbm_delete(VALUE obj, VALUE keystr)

fdbm_modify(obj);
StringValue(keystr);
key.dptr = RSTRING(keystr)->ptr;
key.dsize = RSTRING(keystr)->len;
key.dptr = RSTRING_PTR(keystr);
key.dsize = RSTRING_LEN(keystr);

GetDBM2(obj, dbmp, dbm);

Expand Down Expand Up @@ -348,8 +348,8 @@ fdbm_delete_if(VALUE obj)
for (i = 0; i < RARRAY(ary)->len; i++) {
keystr = RARRAY(ary)->ptr[i];
StringValue(keystr);
key.dptr = RSTRING(keystr)->ptr;
key.dsize = RSTRING(keystr)->len;
key.dptr = RSTRING_PTR(keystr);
key.dsize = RSTRING_LEN(keystr);
if (dbm_delete(dbm, key)) {
rb_raise(rb_eDBMError, "dbm_delete failed");
}
Expand Down Expand Up @@ -438,11 +438,11 @@ fdbm_store(VALUE obj, VALUE keystr, VALUE valstr)
keystr = rb_obj_as_string(keystr);
valstr = rb_obj_as_string(valstr);

key.dptr = RSTRING(keystr)->ptr;
key.dsize = RSTRING(keystr)->len;
key.dptr = RSTRING_PTR(keystr);
key.dsize = RSTRING_LEN(keystr);

val.dptr = RSTRING(valstr)->ptr;
val.dsize = RSTRING(valstr)->len;
val.dptr = RSTRING_PTR(valstr);
val.dsize = RSTRING_LEN(valstr);

GetDBM2(obj, dbmp, dbm);
dbmp->di_size = -1;
Expand Down Expand Up @@ -595,8 +595,8 @@ fdbm_has_key(VALUE obj, VALUE keystr)
DBM *dbm;

StringValue(keystr);
key.dptr = RSTRING(keystr)->ptr;
key.dsize = RSTRING(keystr)->len;
key.dptr = RSTRING_PTR(keystr);
key.dsize = RSTRING_LEN(keystr);

GetDBM2(obj, dbmp, dbm);
val = dbm_fetch(dbm, key);
Expand All @@ -612,14 +612,14 @@ fdbm_has_value(VALUE obj, VALUE valstr)
DBM *dbm;

StringValue(valstr);
val.dptr = RSTRING(valstr)->ptr;
val.dsize = RSTRING(valstr)->len;
val.dptr = RSTRING_PTR(valstr);
val.dsize = RSTRING_LEN(valstr);

GetDBM2(obj, dbmp, dbm);
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
val = dbm_fetch(dbm, key);
if (val.dsize == RSTRING(valstr)->len &&
memcmp(val.dptr, RSTRING(valstr)->ptr, val.dsize) == 0)
if (val.dsize == RSTRING_LEN(valstr) &&
memcmp(val.dptr, RSTRING_PTR(valstr), val.dsize) == 0)
return Qtrue;
}
return Qfalse;
Expand Down
3 changes: 2 additions & 1 deletion ext/dbm/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def db_check(db)
for hdr in $dbm_conf_headers.fetch(db, ["ndbm.h"])
if have_header(hdr.dup) and have_type("DBM", hdr.dup, hsearch)
$defs << hsearch << '-DDBM_HDR="<'+hdr+'>"'
p $defs
return true
end
end
Expand All @@ -55,7 +56,7 @@ def db_prefix(func)

have_header("cdefs.h")
have_header("sys/cdefs.h")
if /DBM_HDR/ =~ $CFLAGS and have_func(db_prefix("dbm_open"))
if /DBM_HDR/ =~ $defs.join(" ") and have_func(db_prefix("dbm_open"))
have_func(db_prefix("dbm_clearerr")) unless $dbm_conf_have_gdbm
create_makefile("dbm")
end
18 changes: 9 additions & 9 deletions ext/digest/digest.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ rb_digest_base_s_digest(VALUE klass, VALUE str)
Data_Get_Struct(obj, void, pctx);

StringValue(str);
algo->update_func(pctx, RSTRING(str)->ptr, RSTRING(str)->len);
algo->update_func(pctx, RSTRING_PTR(str), RSTRING_LEN(str));

str = rb_str_new(0, algo->digest_len);
algo->final_func(RSTRING(str)->ptr, pctx);
algo->final_func(RSTRING_PTR(str), pctx);

return str;
}
Expand All @@ -91,10 +91,10 @@ rb_digest_base_s_hexdigest(VALUE klass, VALUE str)
Data_Get_Struct(obj, void, pctx);

StringValue(str);
algo->update_func(pctx, RSTRING(str)->ptr, RSTRING(str)->len);
algo->update_func(pctx, RSTRING_PTR(str), RSTRING_LEN(str));

str = rb_str_new(0, algo->digest_len * 2);
algo->end_func(pctx, RSTRING(str)->ptr);
algo->end_func(pctx, RSTRING_PTR(str));

return str;
}
Expand Down Expand Up @@ -128,7 +128,7 @@ rb_digest_base_update(VALUE self, VALUE str)
algo = get_digest_base_metadata(rb_obj_class(self));
Data_Get_Struct(self, void, pctx);

algo->update_func(pctx, RSTRING(str)->ptr, RSTRING(str)->len);
algo->update_func(pctx, RSTRING_PTR(str), RSTRING_LEN(str));

return self;
}
Expand Down Expand Up @@ -162,7 +162,7 @@ rb_digest_base_digest(VALUE self)
pctx2 = xmalloc(len);
memcpy(pctx2, pctx1, len);

algo->final_func(RSTRING(str)->ptr, pctx2);
algo->final_func(RSTRING_PTR(str), pctx2);
free(pctx2);

return str;
Expand All @@ -185,7 +185,7 @@ rb_digest_base_hexdigest(VALUE self)
pctx2 = xmalloc(len);
memcpy(pctx2, pctx1, len);

algo->end_func(pctx2, RSTRING(str)->ptr);
algo->end_func(pctx2, RSTRING_PTR(str));
free(pctx2);

return str;
Expand Down Expand Up @@ -213,12 +213,12 @@ rb_digest_base_equal(VALUE self, VALUE other)
StringValue(other);
str2 = other;

if (RSTRING(str2)->len == algo->digest_len)
if (RSTRING_LEN(str2) == algo->digest_len)
str1 = rb_digest_base_digest(self);
else
str1 = rb_digest_base_hexdigest(self);

if (RSTRING(str1)->len == RSTRING(str2)->len
if (RSTRING_LEN(str1) == RSTRING_LEN(str2)
&& rb_str_cmp(str1, str2) == 0)
return Qtrue;

Expand Down
8 changes: 4 additions & 4 deletions ext/etc/etc.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ etc_getpwnam(VALUE obj, VALUE nam)
struct passwd *pwd;

SafeStringValue(nam);
pwd = getpwnam(RSTRING(nam)->ptr);
if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %s", RSTRING(nam)->ptr);
pwd = getpwnam(RSTRING_PTR(nam));
if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %s", RSTRING_PTR(nam));
return setup_passwd(pwd);
#else
return Qnil;
Expand Down Expand Up @@ -351,8 +351,8 @@ etc_getgrnam(VALUE obj, VALUE nam)

rb_secure(4);
SafeStringValue(nam);
grp = getgrnam(RSTRING(nam)->ptr);
if (grp == 0) rb_raise(rb_eArgError, "can't find group for %s", RSTRING(nam)->ptr);
grp = getgrnam(RSTRING_PTR(nam));
if (grp == 0) rb_raise(rb_eArgError, "can't find group for %s", RSTRING_PTR(nam));
return setup_group(grp);
#else
return Qnil;
Expand Down
2 changes: 1 addition & 1 deletion ext/extmk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def $mflags.defined?(var)
end

if $extout
RbConfig.expand(extout = "#$extout", RbConfig::CONFIG.merge("topdir"=>$topdir))
RbConfig.expand(extout = "#{$extout}", RbConfig::CONFIG.merge("topdir"=>$topdir))
if $install
dest = RbConfig.expand($rubylibdir.dup)
unless $destdir.empty?
Expand Down
Loading

0 comments on commit 25c50cd

Please sign in to comment.