Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit e7a6fe1

Browse files
authored
Merge pull request #3852 from dkorpel/parse-int-codesize
Reduce code size of `parseoptions.parse!int()`
2 parents c305472 + 2642c08 commit e7a6fe1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/core/internal/parseoptions.d

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ inout(char)[] find(alias pred)(inout(char)[] str)
168168
}
169169

170170
bool parse(T : size_t)(const(char)[] optname, ref inout(char)[] str, ref T res, const(char)[] errName, bool mayHaveSuffix = false)
171+
if (is(T == size_t))
171172
in { assert(str.length); }
172173
do
173174
{
@@ -242,6 +243,22 @@ do
242243
if (v > res.max)
243244
return parseError("a number " ~ T.max.stringof ~ " or below", optname, str[0 .. i], errName);
244245
str = str[i .. $];
246+
res = v;
247+
return true;
248+
}
249+
250+
bool parse(T : size_t)(const(char)[] optname, ref inout(char)[] str, ref T res, const(char)[] errName, bool mayHaveSuffix = false)
251+
if (!is(T == size_t))
252+
in { assert(str.length); }
253+
do
254+
{
255+
const oldStr = str;
256+
size_t v;
257+
if (!parse!size_t(optname, str, v, errName, mayHaveSuffix))
258+
return false;
259+
260+
if (v > res.max)
261+
return parseError("a number " ~ T.max.stringof ~ " or below", optname, oldStr[0 .. $-str.length], errName);
245262
res = cast(T) v;
246263
return true;
247264
}

0 commit comments

Comments
 (0)