* string.c: refactoring, especially about string flags.
* string.c (STR_UNSET_NOCAPA): removed. Use FL_UNSET() with STR_SHARED. * string.c (rb_str_capacity): check STR_SHARED directly beacuse it is not a embed string. * string.c (rb_str_modify_expand): ditto. * string.c (rb_str_shared_replace): use STR_SET_SHARED(). * string.c (str_make_independent_expand): remove STR_UNSET_NOCAPA() because `str' is not shared string. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44825 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
46fcec9a17
commit
84d8104ed6
17
ChangeLog
17
ChangeLog
@ -1,3 +1,20 @@
|
|||||||
|
Wed Feb 5 12:54:25 2014 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* string.c: refactoring, especially about string flags.
|
||||||
|
|
||||||
|
* string.c (STR_UNSET_NOCAPA): removed.
|
||||||
|
Use FL_UNSET() with STR_SHARED.
|
||||||
|
|
||||||
|
* string.c (rb_str_capacity): check STR_SHARED directly
|
||||||
|
beacuse it is not a embed string.
|
||||||
|
|
||||||
|
* string.c (rb_str_modify_expand): ditto.
|
||||||
|
|
||||||
|
* string.c (rb_str_shared_replace): use STR_SET_SHARED().
|
||||||
|
|
||||||
|
* string.c (str_make_independent_expand): remove STR_UNSET_NOCAPA()
|
||||||
|
because `str' is not shared string.
|
||||||
|
|
||||||
Wed Feb 5 12:11:04 2014 Koichi Sasada <ko1@atdot.net>
|
Wed Feb 5 12:11:04 2014 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* string.c (RESIZE_CAPA): should not resize shared string.
|
* string.c (RESIZE_CAPA): should not resize shared string.
|
||||||
|
31
string.c
31
string.c
@ -49,9 +49,6 @@ VALUE rb_cSymbol;
|
|||||||
|
|
||||||
#define RUBY_MAX_CHAR_LEN 16
|
#define RUBY_MAX_CHAR_LEN 16
|
||||||
#define STR_TMPLOCK FL_USER7
|
#define STR_TMPLOCK FL_USER7
|
||||||
#define STR_UNSET_NOCAPA(s) do {\
|
|
||||||
if (FL_TEST((s),STR_NOEMBED)) FL_UNSET((s),(STR_SHARED));\
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define STR_SET_NOEMBED(str) do {\
|
#define STR_SET_NOEMBED(str) do {\
|
||||||
FL_SET((str), STR_NOEMBED);\
|
FL_SET((str), STR_NOEMBED);\
|
||||||
@ -470,7 +467,7 @@ rb_str_capacity(VALUE str)
|
|||||||
if (STR_EMBED_P(str)) {
|
if (STR_EMBED_P(str)) {
|
||||||
return RSTRING_EMBED_LEN_MAX;
|
return RSTRING_EMBED_LEN_MAX;
|
||||||
}
|
}
|
||||||
else if (STR_NOCAPA_P(str)) {
|
else if (FL_TEST(str, STR_SHARED)) {
|
||||||
return RSTRING(str)->as.heap.len;
|
return RSTRING(str)->as.heap.len;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -952,32 +949,36 @@ rb_str_shared_replace(VALUE str, VALUE str2)
|
|||||||
cr = ENC_CODERANGE(str2);
|
cr = ENC_CODERANGE(str2);
|
||||||
str_discard(str);
|
str_discard(str);
|
||||||
OBJ_INFECT(str, str2);
|
OBJ_INFECT(str, str2);
|
||||||
|
|
||||||
if (RSTRING_LEN(str2) <= RSTRING_EMBED_LEN_MAX) {
|
if (RSTRING_LEN(str2) <= RSTRING_EMBED_LEN_MAX) {
|
||||||
STR_SET_EMBED(str);
|
STR_SET_EMBED(str);
|
||||||
memcpy(RSTRING_PTR(str), RSTRING_PTR(str2), RSTRING_LEN(str2)+1);
|
memcpy(RSTRING_PTR(str), RSTRING_PTR(str2), RSTRING_LEN(str2)+1);
|
||||||
STR_SET_EMBED_LEN(str, RSTRING_LEN(str2));
|
STR_SET_EMBED_LEN(str, RSTRING_LEN(str2));
|
||||||
rb_enc_associate(str, enc);
|
rb_enc_associate(str, enc);
|
||||||
ENC_CODERANGE_SET(str, cr);
|
ENC_CODERANGE_SET(str, cr);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
STR_SET_NOEMBED(str);
|
STR_SET_NOEMBED(str);
|
||||||
STR_UNSET_NOCAPA(str);
|
FL_UNSET(str, STR_SHARED);
|
||||||
RSTRING(str)->as.heap.ptr = RSTRING_PTR(str2);
|
RSTRING(str)->as.heap.ptr = RSTRING_PTR(str2);
|
||||||
RSTRING(str)->as.heap.len = RSTRING_LEN(str2);
|
RSTRING(str)->as.heap.len = RSTRING_LEN(str2);
|
||||||
if (STR_NOCAPA_P(str2)) {
|
|
||||||
|
if (FL_TEST(str2, STR_SHARED)) {
|
||||||
VALUE shared = RSTRING(str2)->as.heap.aux.shared;
|
VALUE shared = RSTRING(str2)->as.heap.aux.shared;
|
||||||
FL_SET(str, RBASIC(str2)->flags & STR_NOCAPA);
|
STR_SET_SHARED(str, shared);
|
||||||
RB_OBJ_WRITE(str, &RSTRING(str)->as.heap.aux.shared, shared);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
RSTRING(str)->as.heap.aux.capa = RSTRING(str2)->as.heap.aux.capa;
|
RSTRING(str)->as.heap.aux.capa = RSTRING(str2)->as.heap.aux.capa;
|
||||||
}
|
}
|
||||||
STR_SET_EMBED(str2); /* abandon str2 */
|
|
||||||
|
/* abandon str2 */
|
||||||
|
STR_SET_EMBED(str2);
|
||||||
RSTRING_PTR(str2)[0] = 0;
|
RSTRING_PTR(str2)[0] = 0;
|
||||||
STR_SET_EMBED_LEN(str2, 0);
|
STR_SET_EMBED_LEN(str2, 0);
|
||||||
rb_enc_associate(str, enc);
|
rb_enc_associate(str, enc);
|
||||||
ENC_CODERANGE_SET(str, cr);
|
ENC_CODERANGE_SET(str, cr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static ID id_to_s;
|
static ID id_to_s;
|
||||||
|
|
||||||
@ -1422,10 +1423,13 @@ static inline int
|
|||||||
str_independent(VALUE str)
|
str_independent(VALUE str)
|
||||||
{
|
{
|
||||||
str_modifiable(str);
|
str_modifiable(str);
|
||||||
if (!STR_SHARED_P(str)) return 1;
|
if (STR_EMBED_P(str) || !FL_TEST(str, STR_SHARED)) {
|
||||||
if (STR_EMBED_P(str)) return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
str_make_independent_expand(VALUE str, long expand)
|
str_make_independent_expand(VALUE str, long expand)
|
||||||
@ -1441,7 +1445,7 @@ str_make_independent_expand(VALUE str, long expand)
|
|||||||
memcpy(ptr, RSTRING_PTR(str), len);
|
memcpy(ptr, RSTRING_PTR(str), len);
|
||||||
}
|
}
|
||||||
STR_SET_NOEMBED(str);
|
STR_SET_NOEMBED(str);
|
||||||
STR_UNSET_NOCAPA(str);
|
FL_UNSET(str, STR_SHARED);
|
||||||
TERM_FILL(ptr + len, termlen);
|
TERM_FILL(ptr + len, termlen);
|
||||||
RSTRING(str)->as.heap.ptr = ptr;
|
RSTRING(str)->as.heap.ptr = ptr;
|
||||||
RSTRING(str)->as.heap.len = len;
|
RSTRING(str)->as.heap.len = len;
|
||||||
@ -1473,7 +1477,6 @@ rb_str_modify_expand(VALUE str, long expand)
|
|||||||
int termlen = TERM_LEN(str);
|
int termlen = TERM_LEN(str);
|
||||||
if (!STR_EMBED_P(str)) {
|
if (!STR_EMBED_P(str)) {
|
||||||
REALLOC_N(RSTRING(str)->as.heap.ptr, char, capa + termlen);
|
REALLOC_N(RSTRING(str)->as.heap.ptr, char, capa + termlen);
|
||||||
STR_UNSET_NOCAPA(str);
|
|
||||||
RSTRING(str)->as.heap.aux.capa = capa;
|
RSTRING(str)->as.heap.aux.capa = capa;
|
||||||
}
|
}
|
||||||
else if (capa + termlen > RSTRING_EMBED_LEN_MAX + 1) {
|
else if (capa + termlen > RSTRING_EMBED_LEN_MAX + 1) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user