Skip to content

Commit 73e2f94

Browse files
committed
buffer read at once
1 parent 4cf1202 commit 73e2f94

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

source/binary/mod.d

+8-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import binary.types;
99
import std.algorithm : each;
1010
import std.bitmanip : read;
1111
import std.exception : enforce;
12-
import std.range : iota;
12+
import std.range : popFrontExactly;
1313
import std.system : Endian;
1414
import std.typecons : Tuple, tuple;
1515

@@ -148,8 +148,8 @@ Data[] decodeDataSection(ref const(ubyte)[] input)
148148
auto memoryIndex = input.leb128!uint();
149149
auto offset = input.decodeExpr();
150150
auto size = input.leb128!uint();
151-
ubyte[] bytes;
152-
iota(size).each!(_ => bytes ~= input.read!ubyte());
151+
auto bytes = cast(ubyte[]) input[0..size];
152+
input.popFrontExactly(size);
153153
data ~= Data(
154154
memoryIndex: memoryIndex,
155155
offset: offset,
@@ -174,11 +174,11 @@ FuncType[] decodeTypeSection(ref const(ubyte)[] input)
174174
{
175175
input.read!ubyte();
176176
uint size = input.leb128!uint();
177-
ValueType[] params;
178-
iota(size).each!(_ => params ~= input.decodeValueSection());
177+
auto params = cast(ValueType[]) input[0..size];
178+
input.popFrontExactly(size);
179179
size = input.leb128!uint();
180-
ValueType[] results;
181-
iota(size).each!(_ => results ~= input.decodeValueSection());
180+
auto results = cast(ValueType[]) input[0..size];
181+
input.popFrontExactly(size);
182182
funcTypes ~= FuncType(params, results);
183183
}
184184
return funcTypes;
@@ -334,10 +334,9 @@ Import[] decodeImportSection(ref const(ubyte)[] input)
334334

335335
string decodeName(ref const(ubyte)[] input)
336336
{
337-
import std.range : popFrontN;
338337
const nameLen = input.leb128!uint();
339338
auto name = cast(string) input[0..nameLen];
340-
input.popFrontN(nameLen);
339+
input.popFrontExactly(nameLen);
341340
return name;
342341
}
343342

0 commit comments

Comments
 (0)