mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
string.c: rename STR_EMBEDABLE_P to STR_EMBEDDABLE_P
* string.c (STR_EMBEDDABLE_P): Renamed from STR_EMBEDABLE_P(). And use it in more places. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
df1c68b2af
commit
eaba77154f
2 changed files with 22 additions and 15 deletions
|
@ -1,3 +1,8 @@
|
|||
Tue Sep 13 21:27:35 2016 Kazuki Yamaguchi <k@rhe.jp>
|
||||
|
||||
* string.c (STR_EMBEDDABLE_P): Renamed from STR_EMBEDABLE_P(). And use
|
||||
it in more places.
|
||||
|
||||
Tue Sep 13 21:23:51 2016 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
|
||||
|
||||
* README.md: Drop support for BeOS now that Haiku is stable since
|
||||
|
|
32
string.c
32
string.c
|
@ -127,7 +127,7 @@ VALUE rb_cSymbol;
|
|||
} while (0)
|
||||
#define RESIZE_CAPA_TERM(str,capacity,termlen) do {\
|
||||
if (STR_EMBED_P(str)) {\
|
||||
if ((capacity) > (RSTRING_EMBED_LEN_MAX + 1 - (termlen))) {\
|
||||
if (!STR_EMBEDDABLE_P(capacity, termlen)) {\
|
||||
char *const tmp = ALLOC_N(char, (capacity)+termlen);\
|
||||
const long tlen = RSTRING_LEN(str);\
|
||||
memcpy(tmp, RSTRING_PTR(str), tlen);\
|
||||
|
@ -165,7 +165,7 @@ VALUE rb_cSymbol;
|
|||
#define SHARABLE_SUBSTRING_P(beg, len, end) 1
|
||||
#endif
|
||||
|
||||
#define STR_EMBEDABLE_P(len, termlen) \
|
||||
#define STR_EMBEDDABLE_P(len, termlen) \
|
||||
((len) <= RSTRING_EMBED_LEN_MAX + 1 - (termlen))
|
||||
|
||||
static VALUE str_replace_shared_without_enc(VALUE str2, VALUE str);
|
||||
|
@ -703,7 +703,7 @@ str_new0(VALUE klass, const char *ptr, long len, int termlen)
|
|||
RUBY_DTRACE_CREATE_HOOK(STRING, len);
|
||||
|
||||
str = str_alloc(klass);
|
||||
if (len > (RSTRING_EMBED_LEN_MAX + 1 - termlen)) {
|
||||
if (!STR_EMBEDDABLE_P(len, termlen)) {
|
||||
RSTRING(str)->as.heap.aux.capa = len;
|
||||
RSTRING(str)->as.heap.ptr = ALLOC_N(char, len + termlen);
|
||||
STR_SET_NOEMBED(str);
|
||||
|
@ -1071,7 +1071,7 @@ str_replace_shared_without_enc(VALUE str2, VALUE str)
|
|||
long len;
|
||||
|
||||
RSTRING_GETMEM(str, ptr, len);
|
||||
if (STR_EMBEDABLE_P(len, termlen)) {
|
||||
if (STR_EMBEDDABLE_P(len, termlen)) {
|
||||
char *ptr2 = RSTRING(str2)->as.ary;
|
||||
STR_SET_EMBED(str2);
|
||||
memcpy(ptr2, RSTRING_PTR(str), len);
|
||||
|
@ -1152,7 +1152,7 @@ str_new_frozen(VALUE klass, VALUE orig)
|
|||
return shared;
|
||||
}
|
||||
}
|
||||
else if (RSTRING_LEN(orig)+TERM_LEN(orig) <= RSTRING_EMBED_LEN_MAX+1) {
|
||||
else if (STR_EMBEDDABLE_P(RSTRING_LEN(orig), TERM_LEN(orig))) {
|
||||
str = str_alloc(klass);
|
||||
STR_SET_EMBED(str);
|
||||
memcpy(RSTRING_PTR(str), RSTRING_PTR(orig), RSTRING_LEN(orig));
|
||||
|
@ -1280,7 +1280,7 @@ str_shared_replace(VALUE str, VALUE str2)
|
|||
OBJ_INFECT(str, str2);
|
||||
termlen = rb_enc_mbminlen(enc);
|
||||
|
||||
if (RSTRING_LEN(str2) <= (RSTRING_EMBED_LEN_MAX + 1 - termlen)) {
|
||||
if (STR_EMBEDDABLE_P(RSTRING_LEN(str2), termlen)) {
|
||||
STR_SET_EMBED(str);
|
||||
memcpy(RSTRING_PTR(str), RSTRING_PTR(str2), RSTRING_LEN(str2)+termlen);
|
||||
STR_SET_EMBED_LEN(str, RSTRING_LEN(str2));
|
||||
|
@ -1899,7 +1899,7 @@ str_make_independent_expand(VALUE str, long len, long expand, const int termlen)
|
|||
|
||||
if (len > capa) len = capa;
|
||||
|
||||
if (capa + termlen - 1 <= RSTRING_EMBED_LEN_MAX && !STR_EMBED_P(str)) {
|
||||
if (!STR_EMBED_P(str) && STR_EMBEDDABLE_P(capa, termlen)) {
|
||||
ptr = RSTRING(str)->as.heap.ptr;
|
||||
STR_SET_EMBED(str);
|
||||
memcpy(RSTRING(str)->as.ary, ptr, len);
|
||||
|
@ -1951,7 +1951,7 @@ rb_str_modify_expand(VALUE str, long expand)
|
|||
REALLOC_N(RSTRING(str)->as.heap.ptr, char, capa + termlen);
|
||||
RSTRING(str)->as.heap.aux.capa = capa;
|
||||
}
|
||||
else if (capa + termlen > RSTRING_EMBED_LEN_MAX + 1) {
|
||||
else if (!STR_EMBEDDABLE_P(capa, termlen)) {
|
||||
str_make_independent_expand(str, len, expand, termlen);
|
||||
}
|
||||
}
|
||||
|
@ -2277,7 +2277,8 @@ rb_str_subseq(VALUE str, long beg, long len)
|
|||
{
|
||||
VALUE str2;
|
||||
|
||||
if ((RSTRING_EMBED_LEN_MAX + 1 - TERM_LEN(str)) < len && SHARABLE_SUBSTRING_P(beg, len, RSTRING_LEN(str))) {
|
||||
if (!STR_EMBEDDABLE_P(len, TERM_LEN(str)) &&
|
||||
SHARABLE_SUBSTRING_P(beg, len, RSTRING_LEN(str))) {
|
||||
long olen;
|
||||
str2 = rb_str_new_shared(rb_str_new_frozen(str));
|
||||
RSTRING(str2)->as.heap.ptr += beg;
|
||||
|
@ -2395,7 +2396,8 @@ str_substr(VALUE str, long beg, long len, int empty)
|
|||
char *p = rb_str_subpos(str, beg, &len);
|
||||
|
||||
if (!p) return Qnil;
|
||||
if (len > (RSTRING_EMBED_LEN_MAX + 1 - TERM_LEN(str)) && SHARABLE_SUBSTRING_P(p, len, RSTRING_END(str))) {
|
||||
if (!STR_EMBEDDABLE_P(len, TERM_LEN(str)) &&
|
||||
SHARABLE_SUBSTRING_P(p, len, RSTRING_END(str))) {
|
||||
long ofs = p - RSTRING_PTR(str);
|
||||
str2 = rb_str_new_frozen(str);
|
||||
str2 = str_new_shared(rb_obj_class(str2), str2);
|
||||
|
@ -2527,14 +2529,14 @@ rb_str_resize(VALUE str, long len)
|
|||
const int termlen = TERM_LEN(str);
|
||||
if (STR_EMBED_P(str)) {
|
||||
if (len == slen) return str;
|
||||
if (STR_EMBEDABLE_P(len, termlen)) {
|
||||
if (STR_EMBEDDABLE_P(len, termlen)) {
|
||||
STR_SET_EMBED_LEN(str, len);
|
||||
TERM_FILL(RSTRING(str)->as.ary + len, termlen);
|
||||
return str;
|
||||
}
|
||||
str_make_independent_expand(str, slen, len - slen, termlen);
|
||||
}
|
||||
else if (STR_EMBEDABLE_P(len, termlen)) {
|
||||
else if (STR_EMBEDDABLE_P(len, termlen)) {
|
||||
char *ptr = STR_HEAP_PTR(str);
|
||||
STR_SET_EMBED(str);
|
||||
if (slen > len) slen = len;
|
||||
|
@ -4232,7 +4234,7 @@ rb_str_drop_bytes(VALUE str, long len)
|
|||
str_modifiable(str);
|
||||
if (len > olen) len = olen;
|
||||
nlen = olen - len;
|
||||
if (nlen <= (RSTRING_EMBED_LEN_MAX + 1 - TERM_LEN(str))) {
|
||||
if (STR_EMBEDDABLE_P(nlen, TERM_LEN(str))) {
|
||||
char *oldptr = ptr;
|
||||
int fl = (int)(RBASIC(str)->flags & (STR_NOEMBED|STR_SHARED|STR_NOFREE));
|
||||
STR_SET_EMBED(str);
|
||||
|
@ -5083,7 +5085,7 @@ rb_str_setbyte(VALUE str, VALUE index, VALUE value)
|
|||
enc = STR_ENC_GET(str);
|
||||
head = RSTRING_PTR(str);
|
||||
ptr = &head[pos];
|
||||
if (len > (RSTRING_EMBED_LEN_MAX + 1 - rb_enc_mbminlen(enc))) {
|
||||
if (!STR_EMBEDDABLE_P(len, rb_enc_mbminlen(enc))) {
|
||||
cr = ENC_CODERANGE(str);
|
||||
switch (cr) {
|
||||
case ENC_CODERANGE_7BIT:
|
||||
|
@ -5137,7 +5139,7 @@ str_byte_substr(VALUE str, long beg, long len, int empty)
|
|||
else
|
||||
p = s + beg;
|
||||
|
||||
if (len > (RSTRING_EMBED_LEN_MAX + 1 - TERM_LEN(str)) && SHARABLE_SUBSTRING_P(beg, len, n)) {
|
||||
if (!STR_EMBEDDABLE_P(len, TERM_LEN(str) && SHARABLE_SUBSTRING_P(beg, len, n))) {
|
||||
str2 = rb_str_new_frozen(str);
|
||||
str2 = str_new_shared(rb_obj_class(str2), str2);
|
||||
RSTRING(str2)->as.heap.ptr += beg;
|
||||
|
|
Loading…
Add table
Reference in a new issue