Skip to content

Commit

Permalink
Use decode instead of parse to decode numbers.
Browse files Browse the repository at this point in the history
  • Loading branch information
deadalnix committed May 31, 2023
1 parent 5b91abc commit aa64387
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
12 changes: 6 additions & 6 deletions src/source/lexnumeric.d
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ mixin template LexNumericImpl(
if (decode) {
overflow |= result >> 56;
result <<= 8;
result |= parseBinDigits(remainingContent);
result |= decodeBinDigits(remainingContent);
}

count += 8;
Expand All @@ -211,7 +211,7 @@ mixin template LexNumericImpl(
if (decode) {
overflow |= result >> (64 - digitCount);
result <<= digitCount;
result |= parseBinDigits(remainingContent, digitCount);
result |= decodeBinDigits(remainingContent, digitCount);
}

count += digitCount;
Expand Down Expand Up @@ -281,7 +281,7 @@ mixin template LexNumericImpl(
if (decode) {
overflow |= result >> 32;
result <<= 32;
result |= parseHexDigits!uint(remainingContent);
result |= decodeHexDigits!uint(remainingContent);
}

count += 8;
Expand All @@ -294,7 +294,7 @@ mixin template LexNumericImpl(
auto shift = 4 * digitCount;
overflow |= result >> (64 - shift);
result <<= shift;
result |= parseHexDigits(remainingContent, digitCount);
result |= decodeHexDigits(remainingContent, digitCount);
}

count += digitCount;
Expand Down Expand Up @@ -358,7 +358,7 @@ mixin template LexNumericImpl(
while (startsWith8DecDigits(remainingContent, state)) {
if (decode) {
auto scaled = result * 100000000;
auto next = parseDecDigits!uint(remainingContent);
auto next = decodeDecDigits!uint(remainingContent);

overflow |= mulhi(result, 100000000);
result = next + scaled;
Expand All @@ -377,7 +377,7 @@ mixin template LexNumericImpl(
if (decode) {
auto p10 = POWERS_OF_10[digitCount];
auto scaled = result * p10;
auto next = parseDecDigits(remainingContent, digitCount);
auto next = decodeDecDigits(remainingContent, digitCount);

overflow |= mulhi(result, p10);
result = next + scaled;
Expand Down
2 changes: 1 addition & 1 deletion src/source/lexstring.d
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ mixin template LexStringImpl(Token,
import std.meta;
alias I = AliasSeq!(ubyte, ushort, uint)[T.sizeof / 2];

result = parseHexDigits!I(rc);
result = decodeHexDigits!I(rc);
index += N;
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/source/swar/bin.d
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private ubyte computeValue(ulong v) {
return v >> 56;
}

ubyte parseBinDigits(string s) in(s.length >= 8) {
ubyte decodeBinDigits(string s) in(s.length >= 8) {
import source.swar.util;
auto v = unalignedLoad!ulong(s);
return computeValue(v);
Expand All @@ -96,11 +96,11 @@ unittest {
) {
ulong state;
assert(startsWith8BinDigits(s, state), s);
assert(parseBinDigits(s) == v, s);
assert(decodeBinDigits(s) == v, s);
}
}

ubyte parseBinDigits(string s, uint count) in(count < 8 && s.length >= count) {
ubyte decodeBinDigits(string s, uint count) in(count < 8 && s.length >= count) {
import source.swar.util;
auto v = read!ulong(s);

Expand All @@ -114,6 +114,6 @@ unittest {
ulong state;
assert(!startsWith8BinDigits(s, state), s);
assert(hasMoreDigits(state));
assert(parseBinDigits(s, getDigitCount(state)) == v, s);
assert(decodeBinDigits(s, getDigitCount(state)) == v, s);
}
}
16 changes: 8 additions & 8 deletions src/source/swar/dec.d
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private auto loadBuffer(T)(string s) in(s.length >= T.sizeof) {
return v - cast(T) 0x3030303030303030;
}

ubyte parseDecDigits(T : ubyte)(string s) in(s.length >= 2) {
ubyte decodeDecDigits(T : ubyte)(string s) in(s.length >= 2) {
uint v = loadBuffer!ushort(s);
v = (2561 * v) >> 8;
return v & 0xff;
Expand All @@ -114,11 +114,11 @@ unittest {
assert(!startsWith8DecDigits(s, state), s);
assert(hasMoreDigits(state));
assert(getDigitCount(state) == 2, s);
assert(parseDecDigits!ubyte(s) == v, s);
assert(decodeDecDigits!ubyte(s) == v, s);
}
}

ushort parseDecDigits(T : ushort)(string s) in(s.length >= 4) {
ushort decodeDecDigits(T : ushort)(string s) in(s.length >= 4) {
// v = [a, b, c, d]
auto v = loadBuffer!uint(s);

Expand All @@ -138,7 +138,7 @@ unittest {
assert(!startsWith8DecDigits(s, state), s);
assert(hasMoreDigits(state));
assert(getDigitCount(state) == 4, s);
assert(parseDecDigits!ushort(s) == v, s);
assert(decodeDecDigits!ushort(s) == v, s);
}
}

Expand All @@ -158,7 +158,7 @@ private uint reduceValue(ulong v) {
return (a + b) >> 32;
}

uint parseDecDigits(T : uint)(string s) in(s.length >= 8) {
uint decodeDecDigits(T : uint)(string s) in(s.length >= 8) {
auto v = loadBuffer!ulong(s);
return reduceValue(v);
}
Expand All @@ -169,11 +169,11 @@ unittest {
"34567890": 34567890, "52350178": 52350178, "99999999": 99999999]) {
ulong state;
assert(startsWith8DecDigits(s, state), s);
assert(parseDecDigits!uint(s) == v, s);
assert(decodeDecDigits!uint(s) == v, s);
}
}

uint parseDecDigits(string s, uint count)
uint decodeDecDigits(string s, uint count)
in(count < 8 && count > 0 && s.length >= count) {
import source.swar.util;
auto v = read!ulong(s);
Expand All @@ -190,6 +190,6 @@ unittest {
ulong state;
assert(!startsWith8DecDigits(s, state), s);
assert(hasMoreDigits(state));
assert(parseDecDigits(s, getDigitCount(state)) == v, s);
assert(decodeDecDigits(s, getDigitCount(state)) == v, s);
}
}
16 changes: 8 additions & 8 deletions src/source/swar/hex.d
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private auto loadBuffer(T)(string s) in(s.length >= T.sizeof) {
return computeValue(v);
}

ubyte parseHexDigits(T : ubyte)(string s) in(s.length >= 2) {
ubyte decodeHexDigits(T : ubyte)(string s) in(s.length >= 2) {
auto v = loadBuffer!ushort(s);
return ((v << 4) | (v >> 8)) & 0xff;
}
Expand All @@ -192,11 +192,11 @@ unittest {
"fE": 0xfe,
]) {
assert(startsWithHexDigits!2(s), s);
assert(parseHexDigits!ubyte(s) == v, s);
assert(decodeHexDigits!ubyte(s) == v, s);
}
}

ushort parseHexDigits(T : ushort)(string s) in(s.length >= 4) {
ushort decodeHexDigits(T : ushort)(string s) in(s.length >= 4) {
// v = [a, b, c, d]
auto v = loadBuffer!uint(s);

Expand Down Expand Up @@ -225,7 +225,7 @@ unittest {
"F1ac": 0xf1ac,
]) {
assert(startsWithHexDigits!4(s), s);
assert(parseHexDigits!ushort(s) == v, s);
assert(decodeHexDigits!ushort(s) == v, s);
}
}

Expand All @@ -245,7 +245,7 @@ private uint reduceValue(ulong v) {
return (a | b) >> 32;
}

uint parseHexDigits(T : uint)(string s) in(s.length >= 8) {
uint decodeHexDigits(T : uint)(string s) in(s.length >= 8) {
auto v = loadBuffer!ulong(s);
return reduceValue(v);
}
Expand All @@ -266,11 +266,11 @@ unittest {
"0D15EA5E": 0x0d15ea5e,
]) {
assert(startsWithHexDigits!8(s), s);
assert(parseHexDigits!uint(s) == v, s);
assert(decodeHexDigits!uint(s) == v, s);
}
}

uint parseHexDigits(string s, uint count)
uint decodeHexDigits(string s, uint count)
in(count < 8 && count > 0 && s.length >= count) {
import source.swar.util;
auto v = read!ulong(s);
Expand All @@ -296,6 +296,6 @@ unittest {
ulong state;
assert(!startsWith8HexDigits(s, state), s);
assert(hasMoreDigits(state));
assert(parseHexDigits(s, getDigitCount(state)) == v, s);
assert(decodeHexDigits(s, getDigitCount(state)) == v, s);
}
}

0 comments on commit aa64387

Please sign in to comment.