summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-19 15:26:41 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-19 15:26:41 +0000
commit595ce95d3c63a40fb3234cba4c59eb6c8f60faf8 (patch)
treef520078fe0cbff54a683811f8c163a6a74850aeb /parse.y
parent3a2d2af0f713c32b51b5b4a31f53829ff4ba8574 (diff)
downloadruby-595ce95d3c63a40fb3234cba4c59eb6c8f60faf8.tar.gz
parse.y: append directly to delayed content
* parse.y (parser_here_document): append byte sequence directly to the delayed content instead of creating an intermediate string object. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48500 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y16
1 files changed, 13 insertions, 3 deletions
diff --git a/parse.y b/parse.y
index d8a07d06bf..8dc8dbebfd 100644
--- a/parse.y
+++ b/parse.y
@@ -6588,11 +6588,21 @@ parser_here_document(struct parser_params *parser, NODE *here)
ripper_dispatch_scan_event(parser, tSTRING_CONTENT);
}
else {
- if (str ||
- ((len = lex_p - parser->tokp) > 0 &&
- (str = STR_NEW3(parser->tokp, len, enc, func), 1))) {
+ if (str) {
rb_str_append(parser->delayed, str);
}
+ else if ((len = lex_p - parser->tokp) > 0) {
+ if (!(func & STR_FUNC_REGEXP) && rb_enc_asciicompat(enc)) {
+ int cr = ENC_CODERANGE_UNKNOWN;
+ rb_str_coderange_scan_restartable(parser->tokp, lex_p, enc, &cr);
+ if (cr != ENC_CODERANGE_7BIT &&
+ current_enc == rb_usascii_encoding() &&
+ enc != rb_utf8_encoding()) {
+ enc = rb_ascii8bit_encoding();
+ }
+ }
+ rb_enc_str_buf_cat(parser->delayed, parser->tokp, len, enc);
+ }
ripper_dispatch_delayed_token(parser, tSTRING_CONTENT);
}
lex_goto_eol(parser);