update to 0.5.1

This commit is contained in:
Razor12911
2022-05-13 13:01:33 +02:00
parent ba0b997871
commit 1bef4768c8
629 changed files with 17804 additions and 538499 deletions

View File

@@ -371,7 +371,7 @@ begin
T := StreamInfo^.Resource.ToHexString.ToLower + '.res';
S := ReplaceText(S, '<fileres>', T);
S := ReplaceText(S, '<ressize>', Res.ToString);
T := WorkDir[Instance, 0] + T;
T := WorkDir[Instance, 1] + T;
if not FileExists(T) then
with TFileStream.Create(T, fmCreate) do
try
@@ -595,10 +595,9 @@ begin
Res1 + Max(StreamInfo^.OldSize, Res1));
Res2 := PrecompEncodePatch(OldInput, StreamInfo^.OldSize, Buffer, Res1,
Buffer + Res1, Max(StreamInfo^.OldSize, Res1));
Funcs^.LogPatch1(StreamInfo^.OldSize, Res1, Res2, (Res2 > 0) and
((Res2 / Max(StreamInfo^.OldSize, Res1)) <= DIFF_TOLERANCE));
if (Res2 > 0) and ((Res2 / Max(StreamInfo^.OldSize, Res1)) <=
DIFF_TOLERANCE) then
Funcs^.LogPatch1(StreamInfo^.OldSize, Res1, Res2,
Funcs^.AcceptPatch(StreamInfo^.OldSize, Res1, Res2));
if Funcs^.AcceptPatch(StreamInfo^.OldSize, Res1, Res2) then
begin
Output(Instance, Buffer + Res1, Res2);
SetBits(StreamInfo^.Option, 1, 31, 1);

View File

@@ -292,7 +292,7 @@ begin
StreamInfo^.OldSize);
Funcs^.LogProcess(LZ4Codecs[GetBits(StreamInfo^.Option, 0, 5)],
PChar(Params), StreamInfo^.OldSize, StreamInfo^.NewSize, Res1, Result);
if Result then
if Result or (StreamInfo^.Status = TStreamStatus.Predicted) then
break;
end;
if (Result = False) and ((StreamInfo^.Status = TStreamStatus.Predicted) or
@@ -301,10 +301,9 @@ begin
Buffer := Funcs^.Allocator(Instance, Res1 + Max(StreamInfo^.OldSize, Res1));
Res2 := PrecompEncodePatch(OldInput, StreamInfo^.OldSize, Buffer, Res1,
Buffer + Res1, Max(StreamInfo^.OldSize, Res1));
Funcs^.LogPatch1(StreamInfo^.OldSize, Res1, Res2, (Res2 > 0) and
((Res2 / Max(StreamInfo^.OldSize, Res1)) <= DIFF_TOLERANCE));
if (Res2 > 0) and ((Res2 / Max(StreamInfo^.OldSize, Res1)) <= DIFF_TOLERANCE)
then
Funcs^.LogPatch1(StreamInfo^.OldSize, Res1, Res2,
Funcs^.AcceptPatch(StreamInfo^.OldSize, Res1, Res2));
if Funcs^.AcceptPatch(StreamInfo^.OldSize, Res1, Res2) then
begin
Output(Instance, Buffer + Res1, Res2);
SetBits(StreamInfo^.Option, 1, 31, 1);

View File

@@ -322,7 +322,7 @@ begin
StreamInfo^.OldSize);
Funcs^.LogProcess(LZOCodecs[GetBits(StreamInfo^.Option, 0, 5)],
PChar(Params), StreamInfo^.OldSize, StreamInfo^.NewSize, Res1, Result);
if Result then
if Result or (StreamInfo^.Status = TStreamStatus.Predicted) then
break;
end;
if (Result = False) and ((StreamInfo^.Status = TStreamStatus.Predicted) or
@@ -331,10 +331,9 @@ begin
Buffer := Funcs^.Allocator(Instance, Res1 + Max(StreamInfo^.OldSize, Res1));
Res2 := PrecompEncodePatch(OldInput, StreamInfo^.OldSize, Buffer, Res1,
Buffer + Res1, Max(StreamInfo^.OldSize, Res1));
Funcs^.LogPatch1(StreamInfo^.OldSize, Res1, Res2, (Res2 > 0) and
((Res2 / Max(StreamInfo^.OldSize, Res1)) <= DIFF_TOLERANCE));
if (Res2 > 0) and ((Res2 / Max(StreamInfo^.OldSize, Res1)) <= DIFF_TOLERANCE)
then
Funcs^.LogPatch1(StreamInfo^.OldSize, Res1, Res2,
Funcs^.AcceptPatch(StreamInfo^.OldSize, Res1, Res2));
if Funcs^.AcceptPatch(StreamInfo^.OldSize, Res1, Res2) then
begin
Output(Instance, Buffer + Res1, Res2);
SetBits(StreamInfo^.Option, 1, 31, 1);

View File

@@ -70,6 +70,7 @@ procedure PrecompOutput3(Instance: Integer; const Buffer: Pointer;
Size: Integer);
procedure PrecompAddStream(Instance: Integer; Info: PStrInfo1; Codec: PChar;
DepthInfo: PDepthInfo)cdecl;
procedure PrecompTransfer(Instance: Integer; Codec: PChar)cdecl;
implementation
@@ -259,6 +260,7 @@ type
DataStore: TDataStore;
MemOutput1, MemOutput2, MemOutput3: TArray<TMemoryStreamEx>;
CurPos1, CurPos2: TArray<Int64>;
CurTransfer: TArray<String>;
InfoStore1: TArray<TListEx<TEncodeSI>>;
InfoStore2: TArray<TArray<TListEx<TFutureSI>>>;
ISIndex: TArray<Boolean>;
@@ -494,6 +496,37 @@ begin
end;
end;
function PrecompGetCodecIndex(Codec: PChar; Index: PByte;
Option: PInteger): Boolean;
var
I, X, Y: Integer;
S: String;
begin
Result := False;
I := 0;
while PrecompGetCodec(Codec, I, False) <> '' do
begin
for X := Low(Codecs) to High(Codecs) do
begin
for Y := Low(Codecs[X].Names) to High(Codecs[X].Names) do
if SameText(PrecompGetCodec(Codec, I, False), Codecs[X].Names[Y]) then
begin
Index^ := X;
S := PrecompGetCodec(Codec, I, True);
if Codecs[X].Initialised then
if Codecs[X].Parse(PChar(S), Option, @PrecompFunctions) then
begin
Result := True;
break;
end;
end;
if Result then
break;
end;
Inc(I);
end;
end;
procedure PrecompAddStream(Instance: Integer; Info: PStrInfo1; Codec: PChar;
DepthInfo: PDepthInfo);
var
@@ -502,8 +535,7 @@ var
LValid: Boolean;
LCodec: Byte;
LOption: Integer;
I, X, Y: Integer;
S: String;
I: Integer;
begin
if CurDepth[Instance] > 0 then
Inc(Info^.Position, Integer.Size);
@@ -516,30 +548,7 @@ begin
end;
if Codec <> '' then
begin
LValid := False;
I := 0;
while PrecompGetCodec(Codec, I, False) <> '' do
begin
for X := Low(Codecs) to High(Codecs) do
begin
for Y := Low(Codecs[X].Names) to High(Codecs[X].Names) do
if SameText(PrecompGetCodec(Codec, I, False), Codecs[X].Names[Y])
then
begin
LCodec := X;
S := PrecompGetCodec(Codec, I, True);
if Codecs[X].Initialised then
if Codecs[X].Parse(PChar(S), @LOption, @PrecompFunctions) then
begin
LValid := True;
break;
end;
end;
if LValid then
break;
end;
Inc(I);
end;
LValid := PrecompGetCodecIndex(Codec, @LCodec, @LOption);
if not LValid then
begin
MemOutput1[Instance].Position := CurPos1[Instance];
@@ -601,6 +610,12 @@ begin
end;
end;
procedure PrecompTransfer(Instance: Integer; Codec: PChar);
begin
with ComVars1[CurDepth[Instance]] do
CurTransfer[Instance] := String(Codec);
end;
function CheckDB(Dictionary: TSynDictionary; const StreamInfo: TEncodeSI;
var Database: TDatabase): Boolean;
var
@@ -676,6 +691,7 @@ begin
end;
Codecs[I].Scan1(Index, Depth, LPtr, LSize, LSizeEx, @PrecompOutput1,
@PrecompAddStream, @PrecompFunctions);
CurTransfer[Index] := '';
end;
end;
@@ -686,6 +702,9 @@ var
SI1: _StrInfo2;
SI2: TFutureSI;
SI3: TEncodeSI;
LValid: Boolean;
LCodec: Byte;
LOption: Integer;
begin
with ComVars1[Depth] do
try
@@ -715,7 +734,23 @@ begin
NativeInt(SI2.Position - DataStore.Position(Index)), X, @SI1, @J,
@PrecompOutput1, @PrecompFunctions) then
begin
if InRange(SI2.Position + J, DataStore.Position(Index),
LValid := True;
if CurTransfer[Index] <> '' then
begin
LValid := PrecompGetCodecIndex(PChar(CurTransfer[Index]), @LCodec,
@LOption);
if LValid then
begin
SI2.Codec := LCodec;
SI1.Option := LOption;
if System.Pos(SPrecompSep2, CurTransfer[Index]) > 0 then
SI1.Status := TStreamStatus.Predicted
else
SI1.Status := TStreamStatus.None;
end;
CurTransfer[Index] := '';
end;
if LValid and InRange(SI2.Position + J, DataStore.Position(Index),
DataStore.Position(Index) + DataStore.Size(Index)) and
InRange(SI2.Position + J + SI1.OldSize, DataStore.Position(Index),
DataStore.Position(Index) + DataStore.ActualSize(Index)) and
@@ -744,7 +779,27 @@ begin
MemOutput1[Index].Position := CurPos1[Index];
end
else
begin
LValid := False;
if CurTransfer[Index] <> '' then
begin
LValid := PrecompGetCodecIndex(PChar(CurTransfer[Index]), @LCodec,
@LOption);
if LValid then
begin
SI2.Codec := LCodec;
SI2.Option := LOption;
if System.Pos(SPrecompSep2, CurTransfer[Index]) > 0 then
SI2.Status := TStreamStatus.Predicted
else
SI2.Status := TStreamStatus.None;
end;
CurTransfer[Index] := '';
end;
MemOutput1[Index].Position := CurPos1[Index];
if LValid then
continue;
end;
end
else
InfoStore2[Index, (not ISIndex[Index]).ToInteger].Add(SI2);
@@ -762,6 +817,9 @@ var
DBTyp: TDatabase;
DBBool: Boolean;
Errored: Boolean;
LValid: Boolean;
LCodec: Byte;
LOption: Integer;
begin
Result := False;
with ComVars1[Depth] do
@@ -798,6 +856,29 @@ begin
except
Result := False;
end;
LValid := False;
if (CurTransfer[Index] <> '') then
begin
LValid := PrecompGetCodecIndex(PChar(CurTransfer[Index]), @LCodec,
@LOption);
if LValid then
begin
SI2.Codec := LCodec;
SI2.Option := LOption;
if System.Pos(SPrecompSep2, CurTransfer[Index]) > 0 then
SI2.Status := TStreamStatus.Predicted
else
SI2.Status := TStreamStatus.None;
InfoStore1[ThreadIndex][StreamIndex] := SI2;
end;
end;
CurTransfer[Index] := '';
if LValid then
begin
MemOutput1[Index].Position := CurPos1[Index];
Result := Process(ThreadIndex, StreamIndex, Index, Depth);
exit;
end;
if UseDB then
if not DBBool then
begin
@@ -1005,6 +1086,7 @@ begin
SetLength(MemOutput3, Options^.Threads);
SetLength(CurPos1, Options^.Threads);
SetLength(CurPos2, Options^.Threads);
SetLength(CurTransfer, Options^.Threads);
if Options^.LowMem and (J = 0) then
I := 1
else
@@ -1237,6 +1319,7 @@ begin
MemOutput2[I].Position := 0;
CurPos1[I] := 0;
CurPos2[I] := 0;
CurTransfer[I] := '';
if (Depth = 0) and (Length(Tasks) > 1) then
begin
Tasks[I].Perform(EncThread);
@@ -2160,6 +2243,8 @@ PrecompFunctions.LogProcess := PrecompLogProcess;
PrecompFunctions.LogRestore := PrecompLogRestore;
PrecompFunctions.LogPatch1 := PrecompLogPatch1;
PrecompFunctions.LogPatch2 := PrecompLogPatch2;
PrecompFunctions.AcceptPatch := PrecompAcceptPatch;
PrecompFunctions.Transfer := PrecompTransfer;
finalization

View File

@@ -726,7 +726,7 @@ begin
StreamInfo^.OldSize);
Funcs^.LogProcess(OodleCodecs[GetBits(StreamInfo^.Option, 0, 5)],
PChar(Params), StreamInfo^.OldSize, StreamInfo^.NewSize, Res1, Result);
if Result then
if Result or (StreamInfo^.Status = TStreamStatus.Predicted) then
break;
end;
if (Result = False) and ((StreamInfo^.Status = TStreamStatus.Predicted) or
@@ -735,10 +735,9 @@ begin
Buffer := Funcs^.Allocator(Instance, Res1 + Max(StreamInfo^.OldSize, Res1));
Res2 := PrecompEncodePatch(OldInput, StreamInfo^.OldSize, Buffer, Res1,
Buffer + Res1, Max(StreamInfo^.OldSize, Res1));
Funcs^.LogPatch1(StreamInfo^.OldSize, Res1, Res2, (Res2 > 0) and
((Res2 / Max(StreamInfo^.OldSize, Res1)) <= DIFF_TOLERANCE));
if (Res2 > 0) and ((Res2 / Max(StreamInfo^.OldSize, Res1)) <= DIFF_TOLERANCE)
then
Funcs^.LogPatch1(StreamInfo^.OldSize, Res1, Res2,
Funcs^.AcceptPatch(StreamInfo^.OldSize, Res1, Res2));
if Funcs^.AcceptPatch(StreamInfo^.OldSize, Res1, Res2) then
begin
Output(Instance, Buffer + Res1, Res2);
SetBits(StreamInfo^.Option, 1, 31, 1);

View File

@@ -190,7 +190,10 @@ type
Status: Boolean)cdecl;
LogPatch2: procedure(OldSize, NewSize, PatchSize: Integer;
Status: Boolean)cdecl;
Reserved: array [0 .. (PRECOMP_FCOUNT - 1) - 39] of Pointer;
AcceptPatch: function(OldSize, NewSize, PatchSize: Integer): Boolean cdecl;
// 40
Transfer: procedure(Instance: Integer; Codec: PChar)cdecl;
Reserved: array [0 .. (PRECOMP_FCOUNT - 1) - 41] of Pointer;
end;
_PrecompOutput = procedure(Instance: Integer; const Buffer: Pointer;
@@ -349,6 +352,8 @@ function PrecompExecStdio(Instance: Integer;
function PrecompExecStdioSync(Instance: Integer;
Executable, CommandLine, WorkDir: PChar; InBuff: Pointer; InSize: Integer;
Output: _ExecOutput): Boolean cdecl;
function PrecompAcceptPatch(OldSize, NewSize, PatchSize: Integer)
: Boolean cdecl;
var
PrecompFunctions: _PrecompFuncs;
@@ -362,7 +367,6 @@ var
implementation
uses
BDiffEncoder, BDiffDecoder,
ZLibDLL, LZ4DLL, LZODLL, ZSTDDLL, OodleDLL, XDeltaDLL,
SynCommons, SynCrypto;
@@ -1214,6 +1218,16 @@ begin
end;
end;
function PrecompAcceptPatch(OldSize, NewSize, PatchSize: Integer): Boolean;
begin
Result := False;
if PatchSize > 0 then
if DIFF_TOLERANCE <= 1 then
Result := (PatchSize / Max(OldSize, NewSize)) <= DIFF_TOLERANCE
else
Result := PatchSize <= DIFF_TOLERANCE;
end;
initialization
EncodeSICmp := TEncodeSIComparer.Create;

View File

@@ -301,7 +301,7 @@ begin
StreamInfo^.OldSize);
Funcs^.LogProcess(ZSTDCodecs[GetBits(StreamInfo^.Option, 0, 5)],
PChar(Params), StreamInfo^.OldSize, StreamInfo^.NewSize, Res1, Result);
if Result then
if Result or (StreamInfo^.Status = TStreamStatus.Predicted) then
break;
end;
if Res1 < 0 then
@@ -312,10 +312,9 @@ begin
Buffer := Funcs^.Allocator(Instance, Res1 + Max(StreamInfo^.OldSize, Res1));
Res2 := PrecompEncodePatch(OldInput, StreamInfo^.OldSize, Buffer, Res1,
Buffer + Res1, Max(StreamInfo^.OldSize, Res1));
Funcs^.LogPatch1(StreamInfo^.OldSize, Res1, Res2, (Res2 > 0) and
((Res2 / Max(StreamInfo^.OldSize, Res1)) <= DIFF_TOLERANCE));
if (Res2 > 0) and ((Res2 / Max(StreamInfo^.OldSize, Res1)) <= DIFF_TOLERANCE)
then
Funcs^.LogPatch1(StreamInfo^.OldSize, Res1, Res2,
Funcs^.AcceptPatch(StreamInfo^.OldSize, Res1, Res2));
if Funcs^.AcceptPatch(StreamInfo^.OldSize, Res1, Res2) then
begin
Output(Instance, Buffer + Res1, Res2);
SetBits(StreamInfo^.Option, 1, 31, 1);