From 5092d645a33e0023282b9cdcefb6ffcbe09b93cf Mon Sep 17 00:00:00 2001 From: Jack Stouffer Date: Wed, 20 Jul 2016 10:02:00 -0400 Subject: [PATCH] Added const and immutable to several variables in std.uni --- std/uni.d | 180 +++++++++++++++++++++++++++--------------------------- 1 file changed, 89 insertions(+), 91 deletions(-) diff --git a/std/uni.d b/std/uni.d index 0c009cb8a..cfd341c1b 100644 --- a/std/uni.d +++ b/std/uni.d @@ -1114,8 +1114,8 @@ pure nothrow: private T simpleIndex(size_t n) inout { - auto q = n / factor; - auto r = n % factor; + immutable q = n / factor; + immutable r = n % factor; return cast(T)((origin[q] >> bits*r) & mask); } @@ -1127,10 +1127,10 @@ pure nothrow: } body { - auto q = n / factor; - auto r = n % factor; - size_t tgt_shift = bits*r; - size_t word = origin[q]; + immutable q = n / factor; + immutable r = n % factor; + immutable tgt_shift = bits*r; + immutable word = origin[q]; origin[q] = (word & ~(mask<= e) { foreach (i; s..e) @@ -1230,7 +1230,7 @@ pure nothrow: return false; return true; } - size_t pad_e = roundDown(e); + immutable pad_e = roundDown(e); size_t i; for (i=s; i= end) //rounded up >= then end of slice { //nothing to gain, use per element assignment @@ -1301,14 +1301,14 @@ pure nothrow: ptr[i] = val; return; } - size_t pad_end = roundDown(end); // rounded down + immutable pad_end = roundDown(end); // rounded down size_t i; for (i=start; i= curIndex); - size_t numFillers = idx - curIndex; + immutable numFillers = idx - curIndex; addValue!lastLevel(defValue, numFillers); addValue!lastLevel(v, 1); curIndex = idx + 1; @@ -4688,12 +4688,12 @@ template Utf8Matcher() { enum mode = Mode.skipOnMatch; assert(!inp.empty); - auto ch = inp[0]; + immutable ch = inp[0]; static if (hasASCII) { if (ch < 0x80) { - bool r = tab!1[ch]; + immutable r = tab!1[ch]; if (r) inp.popFront(); return r; @@ -4918,7 +4918,7 @@ template Utf16Matcher() { enum mode = Mode.skipOnMatch; assert(!inp.empty); - auto ch = inp[0]; + immutable ch = inp[0]; static if (sizeFlags & 1) { if (ch < 0x80) @@ -4944,7 +4944,7 @@ template Utf16Matcher() { enum mode = Mode.alwaysSkip; assert(!inp.empty); - auto ch = inp[0]; + immutable ch = inp[0]; static if (sizeFlags & 1) { if (ch < 0x80) @@ -5703,10 +5703,10 @@ bool propertyNameLess(Char1, Char2)(const(Char1)[] a, const(Char2)[] b) @safe pu @safe uint decompressFrom(const(ubyte)[] arr, ref size_t idx) pure { import std.exception : enforce; - uint first = arr[idx++]; + immutable first = arr[idx++]; if (!(first & 0x80)) // no top bit -> [0..127] return first; - uint extra = ((first>>5) & 1) + 1; // [1, 2] + immutable extra = ((first>>5) & 1) + 1; // [1, 2] uint val = (first & 0x1F); enforce(idx + extra <= arr.length, "bad code point interval encoding"); foreach (j; 0..extra) @@ -6159,7 +6159,7 @@ private: import std.conv : to; import std.internal.unicode_tables : blocks, scripts; // generated file Set set; - bool loaded = loadProperty(name, set) || loadUnicodeSet!(scripts.tab)(name, set) + immutable loaded = loadProperty(name, set) || loadUnicodeSet!(scripts.tab)(name, set) || (name.length > 2 && ucmp(name[0..2],"In") == 0 && loadUnicodeSet!(blocks.tab)(name[2..$], set)); if (loaded) @@ -6809,7 +6809,7 @@ private: void convertToBig() { import core.stdc.stdlib : malloc; - size_t k = smallLength; + immutable k = smallLength; ubyte* p = cast(ubyte*)enforce(malloc(3*(grow+1)), "malloc failed"); for (int i=0; i sequence - int cmpLR = fullCasedCmp(lhs, rhs, str2); + immutable cmpLR = fullCasedCmp(lhs, rhs, str2); if (!cmpLR) continue; // then rhs to sequence - int cmpRL = fullCasedCmp(rhs, lhs, str1); + immutable cmpRL = fullCasedCmp(rhs, lhs, str1); if (!cmpRL) continue; // cmpXX contain remapped codepoints // to obtain stable ordering of icmp - diff = cmpLR - cmpRL; - return diff; + return cmpLR - cmpRL; } } @@ -7367,17 +7365,17 @@ public dchar compose(dchar first, dchar second) pure nothrow import std.algorithm.iteration : map; import std.internal.unicode_comp : compositionTable, composeCntShift, composeIdxMask; import std.range : assumeSorted; - size_t packed = compositionJumpTrie[first]; + immutable packed = compositionJumpTrie[first]; if (packed == ushort.max) return dchar.init; // unpack offset and length - size_t idx = packed & composeIdxMask, cnt = packed >> composeCntShift; + immutable idx = packed & composeIdxMask, cnt = packed >> composeCntShift; // TODO: optimize this micro binary search (no more then 4-5 steps) auto r = compositionTable[idx..idx+cnt].map!"a.rhs"().assumeSorted(); - auto target = r.lowerBound(second).length; + immutable target = r.lowerBound(second).length; if (target == cnt) return dchar.init; - auto entry = compositionTable[idx+target]; + immutable entry = compositionTable[idx+target]; if (entry.rhs != second) return dchar.init; return entry.composed; @@ -7423,7 +7421,7 @@ public Grapheme decompose(UnicodeDecomposition decompType=Canonical)(dchar ch) alias table = decompCompatTable; alias mapping = compatMappingTrie; } - ushort idx = mapping[ch]; + immutable idx = mapping[ch]; if (!idx) // not found, check hangul arithmetic decomposition return decomposeHangul(ch); auto decomp = table[idx..$].until(0); @@ -7493,9 +7491,9 @@ void hangulRecompose(dchar[] seq) pure nothrow @nogc { if (isJamoL(seq[idx]) && isJamoV(seq[idx+1])) { - int indexL = seq[idx] - jamoLBase; - int indexV = seq[idx+1] - jamoVBase; - int indexLV = indexL * jamoNCount + indexV * jamoTCount; + immutable int indexL = seq[idx] - jamoLBase; + immutable int indexV = seq[idx+1] - jamoVBase; + immutable int indexLV = indexL * jamoNCount + indexV * jamoTCount; if (idx + 2 < seq.length && isJamoT(seq[idx+2])) { seq[idx] = jamoSBase + indexLV + seq[idx+2] - jamoTBase; @@ -7524,14 +7522,14 @@ public: */ Grapheme decomposeHangul(dchar ch) { - int idxS = cast(int)ch - jamoSBase; + immutable idxS = cast(int)ch - jamoSBase; if (idxS < 0 || idxS >= jamoSCount) return Grapheme(ch); - int idxL = idxS / jamoNCount; - int idxV = (idxS % jamoNCount) / jamoTCount; - int idxT = idxS % jamoTCount; + immutable idxL = idxS / jamoNCount; + immutable idxV = (idxS % jamoNCount) / jamoTCount; + immutable idxT = idxS % jamoTCount; - int partL = jamoLBase + idxL; - int partV = jamoVBase + idxV; + immutable partL = jamoLBase + idxL; + immutable partV = jamoVBase + idxV; if (idxT > 0) // there is a trailling consonant (T); decomposition return Grapheme(partL, partV, jamoTBase + idxT); else // decomposition @@ -7558,12 +7556,12 @@ dchar composeJamo(dchar lead, dchar vowel, dchar trailing=dchar.init) pure nothr { if (!isJamoL(lead)) return dchar.init; - int indexL = lead - jamoLBase; + immutable indexL = lead - jamoLBase; if (!isJamoV(vowel)) return dchar.init; - int indexV = vowel - jamoVBase; - int indexLV = indexL * jamoNCount + indexV * jamoTCount; - dchar syllable = jamoSBase + indexLV; + immutable indexV = vowel - jamoVBase; + immutable indexLV = indexL * jamoNCount + indexV * jamoTCount; + immutable dchar syllable = jamoSBase + indexLV; return isJamoT(trailing) ? syllable + (trailing - jamoTBase) : syllable; } @@ -7674,7 +7672,7 @@ inout(C)[] normalize(NormalizationForm norm=NFC, C)(inout(C)[] input) foreach (idx, dchar ch; decomposed) { - auto clazz = combiningClass(ch); + immutable clazz = combiningClass(ch); ccc[idx] = clazz; if (clazz == 0 && lastClazz != 0) { @@ -7700,7 +7698,7 @@ inout(C)[] normalize(NormalizationForm norm=NFC, C)(inout(C)[] input) { for (;;) { - auto second = recompose(first, decomposed, ccc); + immutable second = recompose(first, decomposed, ccc); if (second == decomposed.length) break; first = second; @@ -7779,7 +7777,7 @@ private size_t recompose(size_t start, dchar[] input, ubyte[] ccc) pure nothrow { if (i == input.length) break; - int curCC = ccc[i]; + immutable curCC = ccc[i]; // In any character sequence beginning with a starter S // a character C is blocked from S if and only if there // is some character B between S and C, and either B @@ -7793,7 +7791,7 @@ private size_t recompose(size_t start, dchar[] input, ubyte[] ccc) pure nothrow if (curCC > accumCC) { - dchar comp = compose(input[start], input[i]); + immutable comp = compose(input[start], input[i]); if (comp != dchar.init) { input[start] = comp; @@ -7837,7 +7835,7 @@ private auto splitNormalized(NormalizationForm norm, C)(const(C)[] input) lastCC = 0; continue; } - ubyte CC = combiningClass(ch); + immutable ubyte CC = combiningClass(ch); if (lastCC > CC && CC != 0) { return seekStable!norm(idx, input); @@ -8106,7 +8104,7 @@ private S toCase(alias indexFn, uint maxIdx, alias tableFn, alias asciiConvert, { auto val = tableFn(idx); // unpack length + codepoint - uint len = val>>24; + immutable uint len = val>>24; result.put(cast(dchar)(val & 0xFF_FFFF)); foreach (j; idx+1..idx+len) result.put(tableFn(j)); @@ -8171,7 +8169,7 @@ private auto toCaser(alias indexFn, uint maxIdx, alias tableFn, alias asciiConve } else { - auto val = tableFn(idx); + immutable val = tableFn(idx); // unpack length + codepoint nLeft = val >> 24; if (nLeft == 0) @@ -8361,7 +8359,7 @@ private auto toCapitalizer(alias indexFnUpper, uint maxIdxUpper, alias tableFnUp if (!nLeft) { - dchar c = r.front; + immutable dchar c = r.front; const idx = indexFnUpper(c); if (idx == ushort.max) { @@ -8375,7 +8373,7 @@ private auto toCapitalizer(alias indexFnUpper, uint maxIdxUpper, alias tableFnUp } else { - auto val = tableFnUpper(idx); + immutable val = tableFnUpper(idx); // unpack length + codepoint nLeft = val >> 24; if (nLeft == 0) @@ -8640,9 +8638,9 @@ private void toCaseInPlace(alias indexFn, uint maxIdx, alias tableFn, C)(ref C[] while (curIdx != s.length) { size_t startIdx = curIdx; - dchar ch = decode(s, curIdx); + immutable ch = decode(s, curIdx); // TODO: special case for ASCII - auto caseIndex = indexFn(ch); + immutable caseIndex = indexFn(ch); if (caseIndex == ushort.max) // unchanged, skip over { continue; @@ -8653,8 +8651,8 @@ private void toCaseInPlace(alias indexFn, uint maxIdx, alias tableFn, C)(ref C[] // thus can just adjust pointer destIdx = moveTo(s, destIdx, lastUnchanged, startIdx); lastUnchanged = curIdx; - dchar cased = tableFn(caseIndex); - auto casedLen = codeLength!C(cased); + immutable cased = tableFn(caseIndex); + immutable casedLen = codeLength!C(cased); if (casedLen + destIdx > curIdx) // no place to fit cased char { // switch to slow codepath, where we allocate @@ -8691,25 +8689,25 @@ private template toCaseLength(alias indexFn, uint maxIdx, alias tableFn) size_t curIdx = 0; while (curIdx != str.length) { - size_t startIdx = curIdx; - dchar ch = decode(str, curIdx); - ushort caseIndex = indexFn(ch); + immutable startIdx = curIdx; + immutable ch = decode(str, curIdx); + immutable ushort caseIndex = indexFn(ch); if (caseIndex == ushort.max) continue; else if (caseIndex < maxIdx) { codeLen += startIdx - lastNonTrivial; lastNonTrivial = curIdx; - dchar cased = tableFn(caseIndex); + immutable cased = tableFn(caseIndex); codeLen += codeLength!C(cased); } else { codeLen += startIdx - lastNonTrivial; lastNonTrivial = curIdx; - auto val = tableFn(caseIndex); - auto len = val>>24; - dchar cased = val & 0xFF_FFFF; + immutable val = tableFn(caseIndex); + immutable len = val>>24; + immutable dchar cased = val & 0xFF_FFFF; codeLen += codeLength!C(cased); foreach (j; caseIndex+1..caseIndex+len) codeLen += codeLength!C(tableFn(j)); @@ -8744,16 +8742,16 @@ private template toCaseInPlaceAlloc(alias indexFn, uint maxIdx, alias tableFn) size_t lastUnchanged = curIdx; while (curIdx != s.length) { - size_t startIdx = curIdx; // start of current codepoint - dchar ch = decode(s, curIdx); - auto caseIndex = indexFn(ch); + immutable startIdx = curIdx; // start of current codepoint + immutable ch = decode(s, curIdx); + immutable caseIndex = indexFn(ch); if (caseIndex == ushort.max) // skip over { continue; } else if (caseIndex < maxIdx) // 1:1 codepoint mapping { - dchar cased = tableFn(caseIndex); + immutable cased = tableFn(caseIndex); auto toCopy = startIdx - lastUnchanged; ns[destIdx .. destIdx+toCopy] = s[lastUnchanged .. startIdx]; lastUnchanged = curIdx; @@ -8768,7 +8766,7 @@ private template toCaseInPlaceAlloc(alias indexFn, uint maxIdx, alias tableFn) destIdx += toCopy; auto val = tableFn(caseIndex); // unpack length + codepoint - uint len = val>>24; + immutable uint len = val>>24; destIdx = encodeTo(ns, destIdx, cast(dchar)(val & 0xFF_FFFF)); foreach (j; caseIndex+1..caseIndex+len) destIdx = encodeTo(ns, destIdx, tableFn(j));