From a2f40ec3e152da3896ffea843072c73f564bf761 Mon Sep 17 00:00:00 2001 From: Claes Redestad Date: Wed, 5 Jun 2019 10:07:22 +0200 Subject: [PATCH] 8225179: (regex) Minor Pattern cleanup Reviewed-by: igerasim --- .../classes/java/util/regex/Pattern.java | 80 +++++++------------ .../bench/java/util/regex/PatternBench.java | 35 +++++++- 2 files changed, 60 insertions(+), 55 deletions(-) diff --git a/src/java.base/share/classes/java/util/regex/Pattern.java b/src/java.base/share/classes/java/util/regex/Pattern.java index a367ed9417d..f78b5c5473f 100644 --- a/src/java.base/share/classes/java/util/regex/Pattern.java +++ b/src/java.base/share/classes/java/util/regex/Pattern.java @@ -2100,7 +2100,7 @@ loop: for(int x=0, offset=0; x ch < 256 && bits.bits[ch]; boolean isNeg = false; boolean hasBits = false; @@ -2658,9 +2657,9 @@ loop: for(int x=0, offset=0; x ch < 256 && bits[ch]); - this.bits = bits; + bits = new boolean[256]; } BitClass add(int c, int flags) { assert c >= 0 && c <= 255; @@ -3509,8 +3503,12 @@ loop: for(int x=0, offset=0; x is(ch) && p.is(ch)); return ch -> is(ch) && p.is(ch); } diff --git a/test/micro/org/openjdk/bench/java/util/regex/PatternBench.java b/test/micro/org/openjdk/bench/java/util/regex/PatternBench.java index abf084663a2..cc14ed7f0e0 100644 --- a/test/micro/org/openjdk/bench/java/util/regex/PatternBench.java +++ b/test/micro/org/openjdk/bench/java/util/regex/PatternBench.java @@ -45,12 +45,13 @@ public class PatternBench { public String fileTestString; public String flagsString; - public Pattern graphemePattern; public Pattern jmodPattern; public Pattern jmodCanonicalPattern; - public Pattern pattern; + public String charPatternRegex; + public String[] charPatternStrings; + public Pattern charPattern; @Setup public void setup() { @@ -61,6 +62,10 @@ public class PatternBench { String jmodRegex = "^.*(?:(?:_the\\.[^/]*)|(?:_[^/]*\\.marker)|(?:[^/]*\\.diz)|(?:[^/]*\\.debuginfo)|(?:[^/]*\\.dSYM/.*)|(?:[^/]*\\.dSYM)|(?:[^/]*\\.pdb)|(?:[^/]*\\.map))$"; jmodCanonicalPattern = Pattern.compile(jmodRegex, Pattern.CANON_EQ); jmodPattern = Pattern.compile(jmodRegex); + + charPatternRegex = "[ a-zA-Z]*foo[ a-zA-Z0-9]*bar[ a-z]*"; + charPatternStrings = new String[] {"avaaafooddddddbariiii", "lorem ipsum dolor foo bar", "fpp brr lorem ipsum dolor foo bar %", "lorem ipsum dolor foo bar lorem ipsum dolor foo bar lorem ipsum dolor foo bar /"}; + charPattern = Pattern.compile(charPatternRegex); } @Benchmark @@ -83,4 +88,30 @@ public class PatternBench { public boolean normalJmodMatch() { return jmodPattern.matcher(fileTestString).matches(); } + + @Benchmark + @Warmup(iterations = 3) + @Measurement(iterations = 3) + public boolean charPatternMatch() { + return charPattern.matcher(charPatternStrings[0]).matches() + && charPattern.matcher(charPatternStrings[1]).matches() + && charPattern.matcher(charPatternStrings[2]).matches(); + } + + @Benchmark + @Warmup(iterations = 3) + @Measurement(iterations = 3) + public boolean charPatternMatchWithCompile() { + Pattern p = Pattern.compile(charPatternRegex); + return p.matcher(charPatternStrings[0]).matches() + && p.matcher(charPatternStrings[1]).matches() + && p.matcher(charPatternStrings[2]).matches(); + } + + @Benchmark + @Warmup(iterations = 3) + @Measurement(iterations = 3) + public Pattern charPatternCompile() { + return Pattern.compile(charPatternRegex); + } }