From a9c21b97f93efc731e8ac6d726b05ff0b932920e Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Wed, 10 Dec 2014 13:23:00 +0300 Subject: [PATCH] JS parser minor: moved isEndOfLine method to Utils --- .../google/gwt/dev/js/rhino/LineBuffer.java | 14 +++++------ .../com/google/gwt/dev/js/rhino/Utils.java | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 js/js.parser/src/com/google/gwt/dev/js/rhino/Utils.java diff --git a/js/js.parser/src/com/google/gwt/dev/js/rhino/LineBuffer.java b/js/js.parser/src/com/google/gwt/dev/js/rhino/LineBuffer.java index 272b13ebd11..5cb7c34f094 100644 --- a/js/js.parser/src/com/google/gwt/dev/js/rhino/LineBuffer.java +++ b/js/js.parser/src/com/google/gwt/dev/js/rhino/LineBuffer.java @@ -39,6 +39,8 @@ package com.google.gwt.dev.js.rhino; import java.io.Reader; import java.io.IOException; +import static com.google.gwt.dev.js.rhino.Utils.isEndOfLine; + /** * An input buffer that combines fast character-based access with * (slower) support for retrieving the text of the current line. It @@ -118,7 +120,7 @@ final class LineBuffer { return; offset--; int c = buffer[offset]; - if ((c & EOL_HINT_MASK) == 0 && eolChar(c)) { + if ((c & EOL_HINT_MASK) == 0 && isEndOfLine(c)) { lineStart = prevStart; lineno--; } @@ -153,7 +155,7 @@ final class LineBuffer { } int c = buffer[offset]; - if ((c & EOL_HINT_MASK) == 0 && eolChar(c)) { + if ((c & EOL_HINT_MASK) == 0 && isEndOfLine(c)) { return '\n'; } if (c < 128 || !formatChar(c)) { @@ -166,7 +168,7 @@ final class LineBuffer { boolean match(int test) throws IOException { // 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(); // Format chars are not allowed either if (test >= 128 && formatChar(test)) @@ -214,7 +216,7 @@ final class LineBuffer { end += charsRead; } int c = buffer[i]; - if ((c & EOL_HINT_MASK) == 0 && eolChar(c)) + if ((c & EOL_HINT_MASK) == 0 && isEndOfLine(c)) break; i++; } @@ -310,10 +312,6 @@ final class LineBuffer { 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 // true only when (c & EOL_HINT_MASK) == 0 private static final int EOL_HINT_MASK = 0xdfd0; diff --git a/js/js.parser/src/com/google/gwt/dev/js/rhino/Utils.java b/js/js.parser/src/com/google/gwt/dev/js/rhino/Utils.java new file mode 100644 index 00000000000..baf204552de --- /dev/null +++ b/js/js.parser/src/com/google/gwt/dev/js/rhino/Utils.java @@ -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'; + } +}