[jruby-joni] 122/279: Optimize node lower-casing for single byte and do not copy template if it's all lower case.
Hideki Yamane
henrich at moszumanska.debian.org
Mon Nov 16 11:27:11 UTC 2015
This is an automated email from the git hooks/post-receive script.
henrich pushed a commit to branch debian/sid
in repository jruby-joni.
commit ad33ce396ad672b0aa5ef739ab756f21d42fa8c1
Author: Marcin Mielzynski <lopx at gazeta.pl>
Date: Tue Feb 21 03:28:39 2012 +0100
Optimize node lower-casing for single byte and do not copy template if
it's all lower case.
---
src/org/joni/Analyser.java | 71 ++++++++++++++++++++++++++++++++++---------
test/org/joni/test/TestA.java | 4 +++
2 files changed, 61 insertions(+), 14 deletions(-)
diff --git a/src/org/joni/Analyser.java b/src/org/joni/Analyser.java
index 5ecfe59..4d1b25c 100644
--- a/src/org/joni/Analyser.java
+++ b/src/org/joni/Analyser.java
@@ -1401,29 +1401,72 @@ final class Analyser extends Parser {
} // while
}
- private void updateStringNodeCaseFold(Node node) {
- StringNode sn = (StringNode)node;
-
- byte[]sbuf = new byte[sn.length() << 1];
+ private void updateStringNodeCaseFoldSingleByte(StringNode sn, byte[]toLower) {
+ int end = sn.end;
+ byte[]bytes = sn.bytes;
int sp = 0;
+ int p = sn.p;
- value = sn.p;
- int end = sn.end;
+ while (p < end) {
+ byte lower = toLower[bytes[p] & 0xff];
+ if (lower != bytes[p]) {
+ byte[]sbuf = new byte[end - sn.p];
+ System.arraycopy(bytes, sn.p, sbuf, 0, sp);
+
+ while (p < end) sbuf[sp++] = toLower[bytes[p++] & 0xff];
+
+ sn.set(sbuf, 0, sp);
+ break;
+ } else {
+ sp++;
+ p++;
+ }
+ }
+ }
+ private void updateStringNodeCaseFoldMultiByte(StringNode sn) {
+ int end = sn.end;
+ value = sn.p;
+ int sp = 0;
byte[]buf = new byte[Config.ENC_MBC_CASE_FOLD_MAXLEN];
+
while (value < end) {
- int len = enc.mbcCaseFold(regex.caseFoldFlag, sn.bytes, this, end, buf);
- for (int i=0; i<len; i++) {
- if (sp >= sbuf.length) {
- byte[]tmp = new byte[sbuf.length << 1];
- System.arraycopy(sbuf, 0, tmp, 0, sbuf.length);
- sbuf = tmp;
+ int ovalue = value;
+ int len = enc.mbcCaseFold(regex.caseFoldFlag, bytes, this, end, buf);
+
+ for (int i = 0; i < len; i++) {
+ if (bytes[ovalue + i] != buf[i]) {
+
+ byte[]sbuf = new byte[sn.length() << 1];
+ System.arraycopy(bytes, sn.p, sbuf, 0, ovalue - sn.p);
+ value = ovalue;
+ while (value < end) {
+ len = enc.mbcCaseFold(regex.caseFoldFlag, bytes, this, end, buf);
+ for (i = 0; i < len; i++) {
+ if (sp >= sbuf.length) {
+ byte[]tmp = new byte[sbuf.length << 1];
+ System.arraycopy(sbuf, 0, tmp, 0, sbuf.length);
+ sbuf = tmp;
+ }
+ sbuf[sp++] = buf[i];
+ }
+ }
+ sn.set(sbuf, 0, sp);
+ return;
}
- sbuf[sp++] = buf[i];
+ sp++;
}
}
+ }
- sn.set(sbuf, 0, sp);
+ private void updateStringNodeCaseFold(Node node) {
+ StringNode sn = (StringNode)node;
+ byte[] toLower = enc.toLowerCaseTable();
+ if (toLower != null) {
+ updateStringNodeCaseFoldSingleByte(sn, toLower);
+ } else {
+ updateStringNodeCaseFoldMultiByte(sn);
+ }
}
private Node expandCaseFoldMakeRemString(byte[]bytes, int p, int end) {
diff --git a/test/org/joni/test/TestA.java b/test/org/joni/test/TestA.java
index 0a317fa..5654169 100644
--- a/test/org/joni/test/TestA.java
+++ b/test/org/joni/test/TestA.java
@@ -491,6 +491,10 @@ public class TestA extends Test {
ns("\\A[a-f&&[^b-c]&&[^e]]\\z", "e");
ns("[[^a]&&e&&[^e]]", "e");
+
+ x2s("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0, 35, Option.IGNORECASE);
+ x2s("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 0, 35, Option.IGNORECASE);
+ x2s("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaAAAAAAAAAAAAAAAAA", 0, 35, Option.IGNORECASE);
}
public static void main(String[] args) throws Throwable{
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jruby-joni.git
More information about the pkg-java-commits
mailing list