JS parser minor: moved isEndOfLine method to Utils

This commit is contained in:
Alexey Tsvetkov
2014-12-10 13:23:00 +03:00
parent 7c6629e38a
commit a9c21b97f9
2 changed files with 29 additions and 8 deletions
@@ -39,6 +39,8 @@ package com.google.gwt.dev.js.rhino;
import java.io.Reader; import java.io.Reader;
import java.io.IOException; import java.io.IOException;
import static com.google.gwt.dev.js.rhino.Utils.isEndOfLine;
/** /**
* An input buffer that combines fast character-based access with * An input buffer that combines fast character-based access with
* (slower) support for retrieving the text of the current line. It * (slower) support for retrieving the text of the current line. It
@@ -118,7 +120,7 @@ final class LineBuffer {
return; return;
offset--; offset--;
int c = buffer[offset]; int c = buffer[offset];
if ((c & EOL_HINT_MASK) == 0 && eolChar(c)) { if ((c & EOL_HINT_MASK) == 0 && isEndOfLine(c)) {
lineStart = prevStart; lineStart = prevStart;
lineno--; lineno--;
} }
@@ -153,7 +155,7 @@ final class LineBuffer {
} }
int c = buffer[offset]; int c = buffer[offset];
if ((c & EOL_HINT_MASK) == 0 && eolChar(c)) { if ((c & EOL_HINT_MASK) == 0 && isEndOfLine(c)) {
return '\n'; return '\n';
} }
if (c < 128 || !formatChar(c)) { if (c < 128 || !formatChar(c)) {
@@ -166,7 +168,7 @@ final class LineBuffer {
boolean match(int test) throws IOException { boolean match(int test) throws IOException {
// TokenStream never looks ahead for '\n', which allows simple code // TokenStream never looks ahead for '\n', which allows simple code
if ((test & EOL_HINT_MASK) == 0 && eolChar(test)) if ((test & EOL_HINT_MASK) == 0 && isEndOfLine(test))
Context.codeBug(); Context.codeBug();
// Format chars are not allowed either // Format chars are not allowed either
if (test >= 128 && formatChar(test)) if (test >= 128 && formatChar(test))
@@ -214,7 +216,7 @@ final class LineBuffer {
end += charsRead; end += charsRead;
} }
int c = buffer[i]; int c = buffer[i];
if ((c & EOL_HINT_MASK) == 0 && eolChar(c)) if ((c & EOL_HINT_MASK) == 0 && isEndOfLine(c))
break; break;
i++; i++;
} }
@@ -310,10 +312,6 @@ final class LineBuffer {
return Character.getType((char)c) == Character.FORMAT; return Character.getType((char)c) == Character.FORMAT;
} }
private static boolean eolChar(int c) {
return c == '\r' || c == '\n' || c == '\u2028' || c == '\u2029';
}
// Optimization for faster check for eol character: eolChar(c) returns // Optimization for faster check for eol character: eolChar(c) returns
// true only when (c & EOL_HINT_MASK) == 0 // true only when (c & EOL_HINT_MASK) == 0
private static final int EOL_HINT_MASK = 0xdfd0; private static final int EOL_HINT_MASK = 0xdfd0;
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.gwt.dev.js.rhino;
public class Utils {
public static boolean isEndOfLine(int c) {
return c == '\r' || c == '\n' || c == '\u2028' || c == '\u2029';
}
}