8176041: Optimize handling of comment lines in Properties$LineReader.readLine
authorredestad
Thu, 02 Mar 2017 16:18:18 +0100
changeset 44035 f3871cc7914a
parent 44034 0d664fca91a7
child 44036 9897a86c4383
8176041: Optimize handling of comment lines in Properties$LineReader.readLine Reviewed-by: shade, sherman, psandoz
jdk/src/java.base/share/classes/java/util/Properties.java
--- a/jdk/src/java.base/share/classes/java/util/Properties.java	Thu Mar 02 12:43:06 2017 +0100
+++ b/jdk/src/java.base/share/classes/java/util/Properties.java	Thu Mar 02 16:18:18 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -471,7 +471,7 @@
                 if (inStream != null) {
                     //The line below is equivalent to calling a
                     //ISO8859-1 decoder.
-                    c = (char) (0xff & inByteBuf[inOff++]);
+                    c = (char)(inByteBuf[inOff++] & 0xFF);
                 } else {
                     c = inCharBuf[inOff++];
                 }
@@ -494,8 +494,25 @@
                 if (isNewLine) {
                     isNewLine = false;
                     if (c == '#' || c == '!') {
+                        // Comment, quickly consume the rest of the line,
+                        // resume on line-break and backslash.
+                        if (inStream != null) {
+                            while (inOff < inLimit) {
+                                byte b = inByteBuf[inOff++];
+                                if (b == '\n' || b == '\r' || b == '\\') {
+                                    c = (char)(b & 0xFF);
+                                    break;
+                                }
+                            }
+                        } else {
+                            while (inOff < inLimit) {
+                                c = inCharBuf[inOff++];
+                                if (c == '\n' || c == '\r' || c == '\\') {
+                                    break;
+                                }
+                            }
+                        }
                         isCommentLine = true;
-                        continue;
                     }
                 }