Skip to content

Commit e3c4e03

Browse files
committed
Restructure and rename to match Onigmo
This better aligns the code so it's easier to track differences.
1 parent de23ab0 commit e3c4e03

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/org/joni/CodeRangeBuffer.java

+18-12
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,33 @@ public static CodeRangeBuffer addCodeRangeToBuff(CodeRangeBuffer pbuf, ScanEnvir
106106
to = n;
107107
}
108108

109-
if (pbuf == null) pbuf = new CodeRangeBuffer(); // move to CClassNode
109+
int n;
110110

111-
int[]p = pbuf.p;
112-
int n = p[0];
111+
if (pbuf == null) {
112+
pbuf = new CodeRangeBuffer(); // move to CClassNode
113+
n = 0;
114+
} else {
115+
n = pbuf.p[0];
116+
}
117+
118+
int[] data = pbuf.p; // data = bbuf.p
119+
final int dataOff = 1; // data++
113120

114121
int bound = from == 0 ? 0 : n;
115-
int low = 0;
116-
while (low < bound) {
122+
int low;
123+
for (low = 0; low < bound; ) {
117124
int x = (low + bound) >>> 1;
118-
if (from - 1 > p[x * 2 + 2]) {
125+
if (from - 1 > data[dataOff + x * 2 + 1]) {
119126
low = x + 1;
120127
} else {
121128
bound = x;
122129
}
123130
}
124131

125132
int high = to == LAST_CODE_POINT ? n : low;
126-
bound = n;
127-
while (high < bound) {
133+
for (bound = n; high < bound; ) {
128134
int x = (high + bound) >>> 1;
129-
if (to + 1 >= p[x * 2 + 1]) {
135+
if (to + 1 >= data[dataOff + x * 2]) {
130136
high = x + 1;
131137
} else {
132138
bound = x;
@@ -139,11 +145,11 @@ public static CodeRangeBuffer addCodeRangeToBuff(CodeRangeBuffer pbuf, ScanEnvir
139145

140146
if (incN != 1) {
141147
if (checkDup) {
142-
if (from <= p[low * 2 + 2] && (p[low * 2 + 1] <= from || p[low * 2 + 2] <= to)) env.ccDuplicateWarn();
148+
if (from <= data[dataOff + low * 2 + 1] && (data[dataOff + low * 2] <= from || data[dataOff + low * 2 + 1] <= to)) env.ccDuplicateWarn();
143149
}
144150

145-
if (from > p[low * 2 + 1]) from = p[low * 2 + 1];
146-
if (to < p[(high - 1) * 2 + 2]) to = p[(high - 1) * 2 + 2];
151+
if (from > data[dataOff + low * 2]) from = data[dataOff + low * 2];
152+
if (to < data[dataOff + (high - 1) * 2 + 1]) to = data[dataOff + (high - 1) * 2 + 1];
147153
}
148154

149155
if (incN != 0) {

0 commit comments

Comments
 (0)