Skip to content

Commit df6f327

Browse files
committed
chunker.package: Use one Hash instance instead of separate locals
1 parent dab65cb commit df6f327

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

src/chunker/package.d

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -370,32 +370,30 @@ struct Chunker(R)
370370
}
371371

372372
auto add = state.count;
373-
auto window = state.hash.window;
374-
auto wpos = state.hash.wpos;
375-
auto digest = state.hash.digest;
373+
auto hash = state.hash;
376374
foreach (_, b; buf[state.bpos .. state.bmax])
377375
{
378376
// slide(b)
379-
auto out_ = window[wpos];
380-
window[wpos] = b;
381-
digest ^= ulong(tabout[out_].value);
382-
wpos++;
383-
if (wpos >= windowSize)
384-
wpos = 0;
377+
auto out_ = hash.window[hash.wpos];
378+
hash.window[hash.wpos] = b;
379+
hash.digest ^= ulong(tabout[out_].value);
380+
hash.wpos++;
381+
if (hash.wpos >= windowSize)
382+
hash.wpos = 0;
385383

386384
// updateDigest
387-
auto index = cast(ubyte)(digest >> polShift);
388-
digest <<= 8;
389-
digest |= ulong(b);
385+
auto index = cast(ubyte)(hash.digest >> polShift);
386+
hash.digest <<= 8;
387+
hash.digest |= ulong(b);
390388

391-
digest ^= ulong(tabmod[index].value);
389+
hash.digest ^= ulong(tabmod[index].value);
392390
// end manual inline
393391

394392
add++;
395393
if (add < minSize)
396394
continue;
397395

398-
if ((digest&config.splitmask) == 0 || add >= maxSize)
396+
if ((hash.digest&config.splitmask) == 0 || add >= maxSize)
399397
{
400398
auto i = add - state.count - 1;
401399
data ~= state.buf[state.bpos .. state.bpos+uint(i)+1];
@@ -408,7 +406,7 @@ struct Chunker(R)
408406
(
409407
/*Start: */ state.start,
410408
/*Length:*/ state.count,
411-
/*Cut: */ digest,
409+
/*Cut: */ hash.digest,
412410
/*Data: */ data,
413411
);
414412

@@ -417,9 +415,7 @@ struct Chunker(R)
417415
return chunk;
418416
}
419417
}
420-
state.hash.window = window;
421-
state.hash.wpos = wpos;
422-
state.hash.digest = digest;
418+
state.hash = hash;
423419

424420
auto steps = state.bmax - state.bpos;
425421
if (steps > 0)

0 commit comments

Comments
 (0)