Skip to content

Commit ba888b5

Browse files
committed
one test for special cases; if -> switch; fix tabs
Seems to run about 1.5% faster.
1 parent ca142ce commit ba888b5

File tree

1 file changed

+131
-113
lines changed
  • src/vm/jvm/runtime/org/perl6/nqp/runtime

1 file changed

+131
-113
lines changed

src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java

Lines changed: 131 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -4942,9 +4942,9 @@ private static int[] runNFA(ThreadContext tc, NFAInstance nfa, String target, lo
49424942
nextst.clear();
49434943
fates.clear();
49444944

4945-
/* XXX needs to be cached, but tc breaks stage0 when I try */
4946-
long[] longlit = new long[200]; // also needs proper sizing to # of alternatives
4947-
int usedlonglit = 0; // lazy initialization highwater
4945+
/* XXX needs to be cached, but tc breaks stage0 when I try */
4946+
long[] longlit = new long[200]; // also needs proper sizing to # of alternatives
4947+
int usedlonglit = 0; // lazy initialization highwater
49484948

49494949
nextst.add(1);
49504950
while (!nextst.isEmpty() && pos <= eos) {
@@ -4975,117 +4975,135 @@ private static int[] runNFA(ThreadContext tc, NFAInstance nfa, String target, lo
49754975
int act = edgeInfo[i].act;
49764976
int to = edgeInfo[i].to;
49774977

4978-
if (act < 0) {
4979-
act &= 0xff;
4980-
}
4981-
else if (act == NFA.EDGE_FATE) {
4982-
/* Crossed a fate edge. Check if we already saw this, and
4983-
* if so bump the entry we already saw. */
4984-
int arg = edgeInfo[i].arg_i;
4985-
boolean foundFate = false;
4986-
arg &= 0xffffff; // can go away after reboostrap?
4987-
for (int j = 0; j < fates.size(); j++) {
4988-
if (foundFate)
4989-
fates.set(j - 1, fates.get(j));
4990-
if (fates.get(j )== arg) {
4991-
foundFate = true;
4992-
if (j < prevFates)
4993-
prevFates--;
4978+
if (act <= NFA.EDGE_EPSILON) {
4979+
if (act < 0) {
4980+
act &= 0xff;
4981+
}
4982+
else if (act == NFA.EDGE_FATE) {
4983+
/* Crossed a fate edge. Check if we already saw this, and
4984+
* if so bump the entry we already saw. */
4985+
int arg = edgeInfo[i].arg_i;
4986+
boolean foundFate = false;
4987+
arg &= 0xffffff; // can go away after reboostrap?
4988+
for (int j = 0; j < fates.size(); j++) {
4989+
if (foundFate)
4990+
fates.set(j - 1, fates.get(j));
4991+
if (fates.get(j )== arg) {
4992+
foundFate = true;
4993+
if (j < prevFates)
4994+
prevFates--;
4995+
}
49944996
}
4997+
if (arg < usedlonglit)
4998+
arg -= longlit[arg] << 24;
4999+
if (foundFate)
5000+
fates.set(fates.size() - 1, arg);
5001+
else
5002+
fates.add(arg);
5003+
continue;
5004+
}
5005+
else if (act == NFA.EDGE_EPSILON && to <= numStates && done[to] != gen) {
5006+
curst.add(to);
5007+
continue;
49955008
}
4996-
if (arg < usedlonglit)
4997-
arg -= longlit[arg] << 24;
4998-
if (foundFate)
4999-
fates.set(fates.size() - 1, arg);
5000-
else
5001-
fates.add(arg);
5002-
continue;
5003-
}
5004-
else if (act == NFA.EDGE_EPSILON && to <= numStates && done[to] != gen) {
5005-
curst.add(to);
5006-
continue;
50075009
}
50085010

50095011
if (pos >= eos) {
50105012
/* Can't match, so drop state. */
5013+
continue;
50115014
}
5012-
else if (act == NFA.EDGE_CODEPOINT) {
5013-
char arg = (char)edgeInfo[i].arg_i;
5014-
if (target.charAt((int)pos) == arg)
5015-
nextst.add(to);
5016-
}
5017-
else if (act == NFA.EDGE_CODEPOINT_LL) {
5018-
char arg = (char)edgeInfo[i].arg_i;
5019-
if (target.charAt((int)pos) == arg) {
5020-
int fate = (edgeInfo[i].act >> 8) & 0xfffff; /* act is probably signed 32 bits */
5021-
nextst.add(to);
5022-
while (usedlonglit <= fate)
5023-
longlit[usedlonglit++] = 0;
5024-
longlit[fate] = pos - orig_pos;
5015+
5016+
switch (act) {
5017+
case NFA.EDGE_CODEPOINT: {
5018+
char arg = (char)edgeInfo[i].arg_i;
5019+
if (target.charAt((int)pos) == arg)
5020+
nextst.add(to);
5021+
continue;
50255022
}
5026-
}
5027-
else if (act == NFA.EDGE_CODEPOINT_NEG) {
5028-
char arg = (char)edgeInfo[i].arg_i;
5029-
if (target.charAt((int)pos) != arg)
5030-
nextst.add(to);
5031-
}
5032-
else if (act == NFA.EDGE_CHARCLASS) {
5033-
if (iscclass(edgeInfo[i].arg_i, target, pos) != 0)
5034-
nextst.add(to);
5035-
}
5036-
else if (act == NFA.EDGE_CHARCLASS_NEG) {
5037-
if (iscclass(edgeInfo[i].arg_i, target, pos) == 0)
5038-
nextst.add(to);
5039-
}
5040-
else if (act == NFA.EDGE_CHARLIST) {
5041-
String arg = edgeInfo[i].arg_s;
5042-
if (arg.indexOf(target.charAt((int)pos)) >= 0)
5043-
nextst.add(to);
5044-
}
5045-
else if (act == NFA.EDGE_CHARLIST_NEG) {
5046-
String arg = edgeInfo[i].arg_s;
5047-
if (arg.indexOf(target.charAt((int)pos)) < 0)
5048-
nextst.add(to);
5049-
}
5050-
else if (act == NFA.EDGE_CODEPOINT_I) {
5051-
char uc_arg = edgeInfo[i].arg_uc;
5052-
char lc_arg = edgeInfo[i].arg_lc;
5053-
char ord = target.charAt((int)pos);
5054-
if (ord == lc_arg || ord == uc_arg)
5055-
nextst.add(to);
5056-
}
5057-
else if (act == NFA.EDGE_CODEPOINT_I_LL) {
5058-
char uc_arg = edgeInfo[i].arg_uc;
5059-
char lc_arg = edgeInfo[i].arg_lc;
5060-
char ord = target.charAt((int)pos);
5061-
if (ord == lc_arg || ord == uc_arg) {
5062-
int fate = (edgeInfo[i].act >> 8) & 0xfffff; /* act is probably signed 32 bits */
5063-
nextst.add(to);
5064-
while (usedlonglit <= fate)
5065-
longlit[usedlonglit++] = 0;
5066-
longlit[fate] = pos - orig_pos;
5023+
case NFA.EDGE_CODEPOINT_LL: {
5024+
char arg = (char)edgeInfo[i].arg_i;
5025+
if (target.charAt((int)pos) == arg) {
5026+
int fate = (edgeInfo[i].act >> 8) & 0xfffff; /* act is probably signed 32 bits */
5027+
nextst.add(to);
5028+
while (usedlonglit <= fate)
5029+
longlit[usedlonglit++] = 0;
5030+
longlit[fate] = pos - orig_pos;
5031+
}
5032+
continue;
5033+
}
5034+
case NFA.EDGE_CODEPOINT_NEG: {
5035+
char arg = (char)edgeInfo[i].arg_i;
5036+
if (target.charAt((int)pos) != arg)
5037+
nextst.add(to);
5038+
continue;
5039+
}
5040+
case NFA.EDGE_CHARCLASS: {
5041+
if (iscclass(edgeInfo[i].arg_i, target, pos) != 0)
5042+
nextst.add(to);
5043+
continue;
5044+
}
5045+
case NFA.EDGE_CHARCLASS_NEG: {
5046+
if (iscclass(edgeInfo[i].arg_i, target, pos) == 0)
5047+
nextst.add(to);
5048+
continue;
5049+
}
5050+
case NFA.EDGE_CHARLIST: {
5051+
String arg = edgeInfo[i].arg_s;
5052+
if (arg.indexOf(target.charAt((int)pos)) >= 0)
5053+
nextst.add(to);
5054+
continue;
5055+
}
5056+
case NFA.EDGE_CHARLIST_NEG: {
5057+
String arg = edgeInfo[i].arg_s;
5058+
if (arg.indexOf(target.charAt((int)pos)) < 0)
5059+
nextst.add(to);
5060+
continue;
5061+
}
5062+
case NFA.EDGE_CODEPOINT_I: {
5063+
char uc_arg = edgeInfo[i].arg_uc;
5064+
char lc_arg = edgeInfo[i].arg_lc;
5065+
char ord = target.charAt((int)pos);
5066+
if (ord == lc_arg || ord == uc_arg)
5067+
nextst.add(to);
5068+
continue;
5069+
}
5070+
case NFA.EDGE_CODEPOINT_I_LL: {
5071+
char uc_arg = edgeInfo[i].arg_uc;
5072+
char lc_arg = edgeInfo[i].arg_lc;
5073+
char ord = target.charAt((int)pos);
5074+
if (ord == lc_arg || ord == uc_arg) {
5075+
int fate = (edgeInfo[i].act >> 8) & 0xfffff; /* act is probably signed 32 bits */
5076+
nextst.add(to);
5077+
while (usedlonglit <= fate)
5078+
longlit[usedlonglit++] = 0;
5079+
longlit[fate] = pos - orig_pos;
5080+
}
5081+
continue;
5082+
}
5083+
case NFA.EDGE_CODEPOINT_I_NEG: {
5084+
char uc_arg = edgeInfo[i].arg_uc;
5085+
char lc_arg = edgeInfo[i].arg_lc;
5086+
char ord = target.charAt((int)pos);
5087+
if (ord != lc_arg && ord != uc_arg)
5088+
nextst.add(to);
5089+
continue;
5090+
}
5091+
case NFA.EDGE_CHARRANGE: {
5092+
char uc_arg = edgeInfo[i].arg_uc;
5093+
char lc_arg = edgeInfo[i].arg_lc;
5094+
char ord = target.charAt((int)pos);
5095+
if (ord >= lc_arg && ord <= uc_arg)
5096+
nextst.add(to);
5097+
continue;
5098+
}
5099+
case NFA.EDGE_CHARRANGE_NEG: {
5100+
char uc_arg = edgeInfo[i].arg_uc;
5101+
char lc_arg = edgeInfo[i].arg_lc;
5102+
char ord = target.charAt((int)pos);
5103+
if (ord < lc_arg || ord > uc_arg)
5104+
nextst.add(to);
5105+
continue;
50675106
}
5068-
}
5069-
else if (act == NFA.EDGE_CODEPOINT_I_NEG) {
5070-
char uc_arg = edgeInfo[i].arg_uc;
5071-
char lc_arg = edgeInfo[i].arg_lc;
5072-
char ord = target.charAt((int)pos);
5073-
if (ord != lc_arg && ord != uc_arg)
5074-
nextst.add(to);
5075-
}
5076-
else if (act == NFA.EDGE_CHARRANGE) {
5077-
char uc_arg = edgeInfo[i].arg_uc;
5078-
char lc_arg = edgeInfo[i].arg_lc;
5079-
char ord = target.charAt((int)pos);
5080-
if (ord >= lc_arg && ord <= uc_arg)
5081-
nextst.add(to);
5082-
}
5083-
else if (act == NFA.EDGE_CHARRANGE_NEG) {
5084-
char uc_arg = edgeInfo[i].arg_uc;
5085-
char lc_arg = edgeInfo[i].arg_lc;
5086-
char ord = target.charAt((int)pos);
5087-
if (ord < lc_arg || ord > uc_arg)
5088-
nextst.add(to);
50895107
}
50905108
}
50915109
}
@@ -5106,14 +5124,14 @@ else if (act == NFA.EDGE_CHARRANGE_NEG) {
51065124

51075125
/* strip any literal lengths, leaving only fates */
51085126
int[] result = new int[fates.size()];
5109-
if (usedlonglit > 0) {
5110-
for (int i = 0; i < fates.size(); i++)
5111-
result[i] = fates.get(i) & 0xffffff;
5112-
}
5113-
else {
5114-
for (int i = 0; i < fates.size(); i++)
5115-
result[i] = fates.get(i);
5116-
}
5127+
if (usedlonglit > 0) {
5128+
for (int i = 0; i < fates.size(); i++)
5129+
result[i] = fates.get(i) & 0xffffff;
5130+
}
5131+
else {
5132+
for (int i = 0; i < fates.size(); i++)
5133+
result[i] = fates.get(i);
5134+
}
51175135
return result;
51185136
}
51195137

0 commit comments

Comments
 (0)