Skip to content

Commit 1c2632e

Browse files
authored
Merge pull request #4665 from JackStouffer/immutable
[trivial] Added const and immutable to several variables in std.regex.internal.…
2 parents 62588fd + e2ce5a9 commit 1c2632e

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

std/regex/internal/parser.d

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ unittest
8888
{
8989
for (uint pc = start; pc < end; )
9090
{
91-
uint len = code[pc].length;
91+
immutable len = code[pc].length;
9292
if (code[pc].code == IR.GotoEndOr)
9393
break; //pick next alternation branch
9494
if (code[pc].isAtom)
@@ -103,21 +103,21 @@ unittest
103103
if (code[pc].code == IR.LookbehindStart
104104
|| code[pc].code == IR.NeglookbehindStart)
105105
{
106-
uint blockLen = len + code[pc].data
106+
immutable blockLen = len + code[pc].data
107107
+ code[pc].pairedLength;
108108
rev[revPc - blockLen .. revPc] = code[pc .. pc + blockLen];
109109
pc += blockLen;
110110
revPc -= blockLen;
111111
continue;
112112
}
113-
uint second = code[pc].indexOfPair(pc);
114-
uint secLen = code[second].length;
113+
immutable second = code[pc].indexOfPair(pc);
114+
immutable secLen = code[second].length;
115115
rev[revPc - secLen .. revPc] = code[second .. second + secLen];
116116
revPc -= secLen;
117117
if (code[pc].code == IR.OrStart)
118118
{
119119
//we pass len bytes forward, but secLen in reverse
120-
uint revStart = revPc - (second + len - secLen - pc);
120+
immutable revStart = revPc - (second + len - secLen - pc);
121121
uint r = revStart;
122122
uint i = pc + IRL!(IR.OrStart);
123123
while (code[i].code == IR.Option)
@@ -166,7 +166,7 @@ dchar parseUniHex(Char)(ref Char[] str, size_t maxDigit)
166166
uint val;
167167
for (int k = 0; k < maxDigit; k++)
168168
{
169-
auto current = str[k];//accepts ascii only, so it's OK to index directly
169+
immutable current = str[k];//accepts ascii only, so it's OK to index directly
170170
if ('0' <= current && current <= '9')
171171
val = val * 16 + current - '0';
172172
else if ('a' <= current && current <= 'f')
@@ -323,8 +323,8 @@ struct CodeGen
323323
else
324324
{
325325
import std.algorithm.searching : countUntil;
326-
auto ivals = set.byInterval;
327-
auto n = charsets.countUntil(set);
326+
const ivals = set.byInterval;
327+
immutable n = charsets.countUntil(set);
328328
if (n >= 0)
329329
{
330330
if (ivals.length*2 > maxCharsetUsed)
@@ -361,7 +361,7 @@ struct CodeGen
361361
{
362362
nesting++;
363363
pushFixup(length);
364-
uint nglob = groupStack.top++;
364+
immutable nglob = groupStack.top++;
365365
enforce(groupStack.top <= maxGroupNumber, "limit on number of submatches is exceeded");
366366
put(Bytecode(IR.GroupStart, nglob));
367367
}
@@ -372,11 +372,11 @@ struct CodeGen
372372
import std.range : assumeSorted;
373373
nesting++;
374374
pushFixup(length);
375-
uint nglob = groupStack.top++;
375+
immutable nglob = groupStack.top++;
376376
enforce(groupStack.top <= maxGroupNumber, "limit on submatches is exceeded");
377377
auto t = NamedGroup(name, nglob);
378378
auto d = assumeSorted!"a.name < b.name"(dict);
379-
auto ind = d.lowerBound(t).length;
379+
immutable ind = d.lowerBound(t).length;
380380
insertInPlace(dict, ind, t);
381381
put(Bytecode(IR.GroupStart, nglob));
382382
}
@@ -426,7 +426,7 @@ struct CodeGen
426426
void fixRepetition(uint offset)
427427
{
428428
import std.algorithm.mutation : copy;
429-
bool replace = ir[offset].code == IR.Nop;
429+
immutable replace = ir[offset].code == IR.Nop;
430430
if (replace)
431431
{
432432
copy(ir[offset + 1 .. $], ir[offset .. $ - 1]);
@@ -440,8 +440,8 @@ struct CodeGen
440440
static import std.algorithm.comparison;
441441
import std.algorithm.mutation : copy;
442442
import std.array : insertInPlace;
443-
bool replace = ir[offset].code == IR.Nop;
444-
uint len = cast(uint)ir.length - offset - replace;
443+
immutable replace = ir[offset].code == IR.Nop;
444+
immutable len = cast(uint)ir.length - offset - replace;
445445
if (max != infinite)
446446
{
447447
if (min != 1 || max != 1)
@@ -665,7 +665,7 @@ struct Parser(R, Generator)
665665
{
666666
if (re_flags & RegexOption.freeform)
667667
{
668-
bool r = _next();
668+
immutable r = _next();
669669
skipSpace();
670670
return r;
671671
}
@@ -854,7 +854,7 @@ struct Parser(R, Generator)
854854
g.fixAlternation();
855855
break;
856856
default://no groups or whatever
857-
uint start = g.length;
857+
immutable start = g.length;
858858
parseAtom();
859859
parseQuantifier(start);
860860
}
@@ -1274,7 +1274,7 @@ struct Parser(R, Generator)
12741274
//parse and store IR for CodepointSet
12751275
void parseCharset()
12761276
{
1277-
auto save = re_flags;
1277+
const save = re_flags;
12781278
re_flags &= ~RegexOption.freeform; // stop ignoring whitespace if we did
12791279
parseCharsetImpl();
12801280
re_flags = save;
@@ -1439,12 +1439,12 @@ struct Parser(R, Generator)
14391439
g.charsetToIr(CodepointSet);
14401440
break;
14411441
case 'x':
1442-
uint code = parseUniHex(pat, 2);
1442+
immutable code = parseUniHex(pat, 2);
14431443
next();
14441444
g.put(Bytecode(IR.Char,code));
14451445
break;
14461446
case 'u': case 'U':
1447-
uint code = parseUniHex(pat, current == 'u' ? 4 : 8);
1447+
immutable code = parseUniHex(pat, current == 'u' ? 4 : 8);
14481448
next();
14491449
g.put(Bytecode(IR.Char, code));
14501450
break;
@@ -1459,7 +1459,7 @@ struct Parser(R, Generator)
14591459
break;
14601460
case '1': .. case '9':
14611461
uint nref = cast(uint)current - '0';
1462-
uint maxBackref = sum(g.groupStack.data);
1462+
immutable maxBackref = sum(g.groupStack.data);
14631463
enforce(nref < maxBackref, "Backref to unseen group");
14641464
//perl's disambiguation rule i.e.
14651465
//get next digit only if there is such group number
@@ -1573,7 +1573,7 @@ struct Parser(R, Generator)
15731573
case IR.RepeatStart, IR.RepeatQStart:
15741574
uint repEnd = cast(uint)(i + ir[i].data + IRL!(IR.RepeatStart));
15751575
assert(ir[repEnd].code == ir[i].paired.code);
1576-
uint max = ir[repEnd + 4].raw;
1576+
immutable max = ir[repEnd + 4].raw;
15771577
ir[repEnd+2].raw = counterRange.top;
15781578
ir[repEnd+3].raw *= counterRange.top;
15791579
ir[repEnd+4].raw *= counterRange.top;
@@ -1711,7 +1711,7 @@ void optimize(Char)(ref Regex!Char zis)
17111711
{
17121712
if (ir[pc].isStart || ir[pc].isEnd)
17131713
{
1714-
uint dest = ir[pc].indexOfPair(pc);
1714+
immutable dest = ir[pc].indexOfPair(pc);
17151715
assert(dest < ir.length, text("Wrong length in opcode at pc=",
17161716
pc, " ", dest, " vs ", ir.length));
17171717
assert(ir[dest].paired == ir[pc],

0 commit comments

Comments
 (0)