Skip to content

Commit 065f144

Browse files
committedJan 22, 2018
Remove some dead code.
Add tiny optimization where we will not try to look past first seen token for magic comments unless we happen to be running with -w.
1 parent 28db22d commit 065f144

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed
 

Diff for: ‎core/src/main/java/org/jruby/lexer/LexingCommon.java

-6
Original file line numberDiff line numberDiff line change
@@ -818,9 +818,6 @@ public static int magicCommentMarker(ByteList str, int begin) {
818818
return -1;
819819
}
820820

821-
public static final String magicString = "^[^\\S]*([^\\s\'\":;]+)\\s*:\\s*(\"(?:\\\\.|[^\"])*\"|[^\"\\s;]+)[\\s;]*[^\\S]*$";
822-
public static final Regex magicRegexp = new Regex(magicString.getBytes(), 0, magicString.length(), 0, Encoding.load("ASCII"));
823-
824821
public boolean parser_magic_comment(ByteList magicLine) {
825822
boolean indicator = false;
826823
int vbeg, vend;
@@ -840,9 +837,6 @@ public boolean parser_magic_comment(ByteList magicLine) {
840837

841838
/* %r"([^\\s\'\":;]+)\\s*:\\s*(\"(?:\\\\.|[^\"])*\"|[^\"\\s;]+)[\\s;]*" */
842839
while (length > 0) {
843-
int i;
844-
long n = 0;
845-
846840
for (; length > 0; str++, --length) {
847841
char c = magicLine.charAt(str);
848842

Diff for: ‎core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,10 @@ private int yylex() throws IOException {
874874
continue;
875875
case '#': { /* it's a comment */
876876
this.tokenSeen = tokenSeen;
877-
if (!parser_magic_comment(lexb.makeShared(lex_p, lex_pend - lex_p))) {
878-
if (comment_at_top()) set_file_encoding(lex_p, lex_pend);
877+
if (!tokenSeen || !warnings.isVerbose()) {
878+
if (!parser_magic_comment(lexb.makeShared(lex_p, lex_pend - lex_p))) {
879+
if (comment_at_top()) set_file_encoding(lex_p, lex_pend);
880+
}
879881
}
880882
lex_p = lex_pend;
881883
}

0 commit comments

Comments
 (0)
Please sign in to comment.