MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / CopyString

Method CopyString

Libraries/unrar/unpackinline.cpp:13–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11#endif
12
13_forceinline void Unpack::CopyString(uint Length,uint Distance)
14{
15 size_t SrcPtr=UnpPtr-Distance;
16 if (SrcPtr<MaxWinSize-MAX_INC_LZ_MATCH && UnpPtr<MaxWinSize-MAX_INC_LZ_MATCH)
17 {
18 // If we are not close to end of window, we do not need to waste time
19 // to "& MaxWinMask" pointer protection.
20
21 byte *Src=Window+SrcPtr;
22 byte *Dest=Window+UnpPtr;
23 UnpPtr+=Length;
24
25#ifdef FAST_MEMCPY
26 if (Distance<Length) // Overlapping strings
27#endif
28 while (Length>=8)
29 {
30 Dest[0]=Src[0];
31 Dest[1]=Src[1];
32 Dest[2]=Src[2];
33 Dest[3]=Src[3];
34 Dest[4]=Src[4];
35 Dest[5]=Src[5];
36 Dest[6]=Src[6];
37 Dest[7]=Src[7];
38
39 Src+=8;
40 Dest+=8;
41 Length-=8;
42 }
43#ifdef FAST_MEMCPY
44 else
45 while (Length>=8)
46 {
47 // In theory we still could overlap here.
48 // Supposing Distance == MaxWinSize - 1 we have memcpy(Src, Src + 1, 8).
49 // But for real RAR archives Distance <= MaxWinSize - MAX_INC_LZ_MATCH
50 // always, so overlap here is impossible.
51
52 // This memcpy expanded inline by MSVC. We could also use uint64
53 // assignment, which seems to provide about the same speed.
54 memcpy(Dest,Src,8);
55
56 Src+=8;
57 Dest+=8;
58 Length-=8;
59 }
60#endif
61
62 // Unroll the loop for 0 - 7 bytes left. Note that we use nested "if"s.
63 if (Length>0) { Dest[0]=Src[0];
64 if (Length>1) { Dest[1]=Src[1];
65 if (Length>2) { Dest[2]=Src[2];
66 if (Length>3) { Dest[3]=Src[3];
67 if (Length>4) { Dest[4]=Src[4];
68 if (Length>5) { Dest[5]=Src[5];
69 if (Length>6) { Dest[6]=Src[6]; } } } } } } } // Close all nested "if"s.
70 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected