ASF Bugzilla – Attachment 10866 Details for
Bug 27795
Add optimization for regexps which strats with ^(BOL)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Suggested fix (it optimizes matching for non multiline matching only)
27795-patch.txt (text/plain), 3.53 KB, created by
Oleg Sukhodolsky
on 2004-03-19 06:54:36 UTC
(
hide
)
Description:
Suggested fix (it optimizes matching for non multiline matching only)
Filename:
MIME Type:
Creator:
Oleg Sukhodolsky
Created:
2004-03-19 06:54:36 UTC
Size:
3.53 KB
patch
obsolete
>Index: src/java/org/apache/regexp/RE.java >=================================================================== >RCS file: /home/cvspublic/jakarta-regexp/src/java/org/apache/regexp/RE.java,v >retrieving revision 1.21 >diff -c -r1.21 RE.java >*** src/java/org/apache/regexp/RE.java 27 Feb 2004 02:41:20 -0000 1.21 >--- src/java/org/apache/regexp/RE.java 19 Mar 2004 06:51:26 -0000 >*************** >*** 1443,1448 **** >--- 1443,1453 ---- > // Can we optimize the search by looking for a prefix string? > if (program.prefix == null) > { >+ if ((program.flags & REProgram.OPT_STARTS_WITH_BOL) != 0 >+ && (matchFlags & MATCH_MULTILINE) == 0) >+ { >+ return (i == 0) && matchAt(0); >+ } > // Unprefixed matching must try for a match at each character > for ( ;! search.isEnd(i - 1); i++) > { >Index: src/java/org/apache/regexp/REProgram.java >=================================================================== >RCS file: /home/cvspublic/jakarta-regexp/src/java/org/apache/regexp/REProgram.java,v >retrieving revision 1.4 >diff -c -r1.4 REProgram.java >*** src/java/org/apache/regexp/REProgram.java 17 Feb 2004 13:37:54 -0000 1.4 >--- src/java/org/apache/regexp/REProgram.java 19 Mar 2004 06:51:26 -0000 >*************** >*** 33,38 **** >--- 33,39 ---- > public class REProgram implements Serializable > { > static final int OPT_HASBACKREFS = 1; >+ static final int OPT_STARTS_WITH_BOL = 2; > > char[] instruction; // The compiled regular expression 'program' > int lenInstruction; // The amount of the instruction buffer in use >*************** >*** 117,131 **** > { > // to the end node > int next = instruction[0 + RE.offsetNext]; >! if (instruction[next + RE.offsetOpcode] == RE.OP_END) > { >! // and the branch starts with an atom >! if (lenInstruction >= (RE.nodeSize * 2) && instruction[RE.nodeSize + RE.offsetOpcode] == RE.OP_ATOM) > { > // then get that atom as an prefix because there's no other choice > int lenAtom = instruction[RE.nodeSize + RE.offsetOpdata]; > prefix = new char[lenAtom]; > System.arraycopy(instruction, RE.nodeSize * 2, prefix, 0, lenAtom); > } > } > } >--- 118,140 ---- > { > // to the end node > int next = instruction[0 + RE.offsetNext]; >! if (instruction[next + RE.offsetOpcode] == RE.OP_END >! && lenInstruction >= (RE.nodeSize * 2)) > { >! final char nextOp = >! instruction[RE.nodeSize + RE.offsetOpcode]; >! // the branch starts with an atom >! if (nextOp == RE.OP_ATOM) > { > // then get that atom as an prefix because there's no other choice > int lenAtom = instruction[RE.nodeSize + RE.offsetOpdata]; > prefix = new char[lenAtom]; > System.arraycopy(instruction, RE.nodeSize * 2, prefix, 0, lenAtom); >+ } >+ // the branch starts with an BOL >+ else if (nextOp == RE.OP_BOL) >+ { >+ flags |= OPT_STARTS_WITH_BOL; > } > } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 27795
: 10866