mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
string.c: rb_str_concat_literals
* string.c (rb_str_concat_literals): concatenate literal string fragments. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54490 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
eee2769c0d
commit
a491508753
3 changed files with 19 additions and 14 deletions
|
@ -365,13 +365,7 @@ concatstrings
|
||||||
(...)
|
(...)
|
||||||
(VALUE val) // inc += 1 - num;
|
(VALUE val) // inc += 1 - num;
|
||||||
{
|
{
|
||||||
rb_num_t i = num - 1;
|
val = rb_str_concat_literals(num, &TOPN(num-1));
|
||||||
|
|
||||||
val = rb_str_resurrect(TOPN(i));
|
|
||||||
while (i-- > 0) {
|
|
||||||
const VALUE v = TOPN(i);
|
|
||||||
rb_str_append_literal(val, v);
|
|
||||||
}
|
|
||||||
POPN(num);
|
POPN(num);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
23
string.c
23
string.c
|
@ -2677,13 +2677,24 @@ rb_str_append(VALUE str, VALUE str2)
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_str_append_literal(VALUE str, VALUE str2)
|
rb_str_concat_literals(size_t num, const VALUE *strary)
|
||||||
{
|
{
|
||||||
int encidx = rb_enc_get_index(str2);
|
VALUE str;
|
||||||
rb_str_buf_append(str, str2);
|
size_t i;
|
||||||
if (encidx != ENCINDEX_US_ASCII) {
|
|
||||||
if (rb_enc_get_index(str) == ENCINDEX_US_ASCII)
|
if (!num) return rb_str_new(0, 0);
|
||||||
rb_enc_associate_index(str, encidx);
|
str = rb_str_resurrect(strary[0]);
|
||||||
|
for (i = 1; i < num; ++i) {
|
||||||
|
const VALUE v = strary[i];
|
||||||
|
int encidx = ENCODING_GET(v);
|
||||||
|
|
||||||
|
rb_enc_cr_str_buf_cat(str, RSTRING_PTR(v), RSTRING_LEN(v),
|
||||||
|
encidx, ENC_CODERANGE(v), NULL);
|
||||||
|
OBJ_INFECT_RAW(str, v);
|
||||||
|
if (encidx != ENCINDEX_US_ASCII) {
|
||||||
|
if (ENCODING_GET_INLINED(str) == ENCINDEX_US_ASCII)
|
||||||
|
rb_enc_set_index(str, encidx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
2
vm.c
2
vm.c
|
@ -23,7 +23,7 @@
|
||||||
#include "probes.h"
|
#include "probes.h"
|
||||||
#include "probes_helper.h"
|
#include "probes_helper.h"
|
||||||
|
|
||||||
VALUE rb_str_append_literal(VALUE str, VALUE str2);
|
VALUE rb_str_concat_literals(size_t, const VALUE*);
|
||||||
|
|
||||||
static inline VALUE *
|
static inline VALUE *
|
||||||
VM_EP_LEP(VALUE *ep)
|
VM_EP_LEP(VALUE *ep)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue