Skip to content

Commit

Permalink
Refactor ripper StringTerm a little bit. Apparently when we hit tREGE…
Browse files Browse the repository at this point in the history
…XP_END

we go back to lexb for the original string without special processing.  We
were creating an extra StringBuilder (incorrectly) and then concating it onto
another StringBuilder just to throw is away (you're welcome).  So this commit
just removes all that.
enebo committed Nov 21, 2017
1 parent ce61601 commit 58cd133
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions core/src/main/java/org/jruby/ext/ripper/StringTerm.java
Original file line number Diff line number Diff line change
@@ -62,21 +62,14 @@ protected ByteList createByteList(RipperLexer lexer) {
return new ByteList(ByteList.NULL_ARRAY, lexer.getEncoding());
}

private int endFound(RipperLexer lexer, LexerSource src, ByteList buffer) throws IOException {
private int endFound(RipperLexer lexer) throws IOException {
if ((flags & STR_FUNC_QWORDS) != 0) {
flags = -1;
buffer.append(end);
return ' ';
}

if ((flags & STR_FUNC_REGEXP) != 0) {
String options = parseRegexpFlags(lexer, src);
buffer.append(options.getBytes());

return Tokens.tREGEXP_END;
}
if ((flags & STR_FUNC_REGEXP) != 0) return parseRegexpFlags(lexer);

buffer.append(end);
return Tokens.tSTRING_END;
}

@@ -104,7 +97,7 @@ public int parseString(RipperLexer lexer, LexerSource src) throws IOException {
}

if (c == end && nest == 0) {
return endFound(lexer, src, buffer);
return endFound(lexer);
}

if (spaceSeen) {
@@ -144,9 +137,7 @@ public int parseString(RipperLexer lexer, LexerSource src) throws IOException {
return Tokens.tSTRING_CONTENT;
}

private String parseRegexpFlags(RipperLexer lexer, LexerSource src) throws IOException {
StringBuilder buf = new StringBuilder(end);

private int parseRegexpFlags(RipperLexer lexer) throws IOException {
int c;
StringBuilder unknownFlags = new StringBuilder(10);

@@ -155,7 +146,6 @@ private String parseRegexpFlags(RipperLexer lexer, LexerSource src) throws IOExc
switch (c) {
case 'i': case 'x': case 'm': case 'o': case 'n':
case 'e': case 's': case 'u':
buf.append((char) c);
break;
default:
unknownFlags.append((char) c);
@@ -166,7 +156,8 @@ private String parseRegexpFlags(RipperLexer lexer, LexerSource src) throws IOExc
if (unknownFlags.length() != 0) {
lexer.compile_error("unknown regexp option" + (unknownFlags.length() > 1 ? "s" : "") + " - " + unknownFlags.toString());
}
return buf.toString();

return Tokens.tREGEXP_END;
}

private void mixedEscape(RipperLexer lexer, Encoding foundEncoding, Encoding parserEncoding) {

0 comments on commit 58cd133

Please sign in to comment.