Permalink
Browse files

new SplitRights() function - also include some refactoring to please …

…FPC on ARM
  • Loading branch information...
Arnaud Bouchez
Arnaud Bouchez committed Sep 2, 2018
1 parent a17c2f1 commit c6ba9fc8d87a722c8499579c378993d0df031ab5
Showing with 44 additions and 17 deletions.
  1. +35 −9 SynCommons.pas
  2. +4 −4 SynLZ.pas
  3. +4 −3 SynLog.pas
  4. +1 −1 SynopseCommit.inc
@@ -2910,6 +2910,12 @@ procedure Split(const Str: RawUTF8; const SepStr: array of RawUTF8;
// - if SepChar doesn't appear, will return Str, e.g. SplitRight('123','/')='123'
function SplitRight(const Str: RawUTF8; SepChar: AnsiChar): RawUTF8;
/// returns the last occurence of the given SepChar separated context
// - e.g. SplitRight('path/one\two/file.ext','/\')='file.ext', i.e.
// SepChars='/\' will be like ExtractFileName() over RawUTF8 string
// - if SepChar doesn't appear, will return Str, e.g. SplitRight('123','/')='123'
function SplitRights(const Str, SepChar: RawUTF8): RawUTF8;
/// fast version of StringReplace(S, OldPattern, NewPattern,[rfReplaceAll]);
function StringReplaceAll(const S, OldPattern, NewPattern: RawUTF8): RawUTF8;
@@ -16072,14 +16078,14 @@ TSynMonitorInputOutput = class(TSynMonitor)
procedure LockedPerSecProperties; override;
procedure LockedSum(another: TSynMonitor); override;
public
/// increase the internal size counters
// - thread-safe method
procedure AddSize(const Incoming, Outgoing: QWord);
published
/// initialize the instance nested class properties
constructor Create; override;
/// finalize the instance
destructor Destroy; override;
/// increase the internal size counters
// - thread-safe method
procedure AddSize(const Incoming, Outgoing: QWord);
published
/// how many data has been received
property Input: TSynMonitorSize read fInput;
/// how many data has been sent back
@@ -22954,7 +22960,7 @@ procedure FillZero(var dest; count: PtrInt);
{$endif}
function SplitRight(const Str: RawUTF8; SepChar: AnsiChar): RawUTF8;
var i: integer;
var i: PtrInt;
begin
for i := length(Str) downto 1 do
if Str[i]=SepChar then begin
@@ -22964,6 +22970,26 @@ function SplitRight(const Str: RawUTF8; SepChar: AnsiChar): RawUTF8;
result := Str;
end;
function SplitRights(const Str, SepChar: RawUTF8): RawUTF8;
var i, j, sep: PtrInt;
c: AnsiChar;
begin
sep := length(SepChar);
if sep > 0 then
if sep = 1 then
result := SplitRight(Str,SepChar[1]) else begin
for i := length(Str) downto 1 do begin
c := Str[i];
for j := 1 to sep do
if c=SepChar[j] then begin
result := copy(Str,i+1,maxInt);
exit;
end;
end;
end;
result := Str;
end;
function Split(const Str, SepStr: RawUTF8; StartPos: integer): RawUTF8;
var i: integer;
begin
@@ -37628,8 +37654,8 @@ function GetMimeContentType(Content: Pointer; Len: integer;
// 1 5 9 14 18 23 27 31 35 40 44 47 51 55 59
'atom,rdf,rss,webp,appc,mani,docx,xml,json,woff,ogg,ogv,mp4,m2v,'+
// 63 68 72 76 81 86 91 96 100 105 110 114 118 122
'm2p,mp3,h264,gz') of
// 126 130 134 139
'm2p,mp3,h264,text,log,gz') of
// 126 130 134 139 144 148
1: result := 'image/png';
5: result := 'image/gif';
9: result := 'image/tiff';
@@ -37642,7 +37668,7 @@ function GetMimeContentType(Content: Pointer; Len: integer;
// text/javascript and application/x-javascript are obsolete (RFC 4329)
47: result := 'image/x-icon';
51,105: result := 'application/font-woff';
55: result := TEXT_CONTENT_TYPE;
55,139,144: result := TEXT_CONTENT_TYPE;
59: result := 'image/svg+xml';
63,68,72,96: result := XML_CONTENT_TYPE;
76: result := 'image/webp';
@@ -37653,7 +37679,7 @@ function GetMimeContentType(Content: Pointer; Len: integer;
122,126: result := 'video/mp2';
130: result := 'audio/mpeg'; // RFC 3003
134: result := 'video/H264'; // RFC 6184
139: result := 'application/gzip';
148: result := 'application/gzip';
else
if result<>'' then
result := 'application/'+copy(result,2,10);
@@ -464,7 +464,7 @@ function SynLZcompress1(src: PAnsiChar; size: integer; dst: PAnsiChar): integer;
{$else CPUX86}
function SynLZcompress1(src: PAnsiChar; size: integer; dst: PAnsiChar): integer;
var off: TOffsets;
cache: array[0..4095] of cardinal; // uses 32B+16KB=48KB on stack
cache: array[0..4095] of cardinal; // uses 32KB+16KB=48KB on stack
asm // rcx=src, edx=size, r8=dest
{$ifndef win64} // Linux 64-bit ABI
mov r8, rdx
@@ -660,7 +660,7 @@ function SynLZcompress1pas(src: PAnsiChar; size: integer; dst: PAnsiChar): integ
cached := v xor cache[h]; // o=nil if cache[h] is uninitialized
cache[h] := v;
if (cached and $00ffffff=0) and (o<>nil) and (src-o>2) then begin
CWpoint^ := CWpoint^ or (1 shl CWbit);
CWpoint^ := CWpoint^ or (cardinal(1) shl CWbit);
inc(src,2);
inc(o,2);
t := 1;
@@ -1363,7 +1363,7 @@ function SynLZcompress2(src: PAnsiChar; size: integer; dst: PAnsiChar): integer;
end;
end;
end else begin
CWpoint^ := CWpoint^ or (1 shl CWbit);
CWpoint^ := CWpoint^ or (cardinal(1) shl CWbit);
dec(v,9);
if v>15 then begin
v := 15; // v=9..24 -> h=0..15
@@ -1393,7 +1393,7 @@ function SynLZcompress2(src: PAnsiChar; size: integer; dst: PAnsiChar): integer;
end;
// assert(PWord(o)^=PWord(src)^);
tdiff := 0;
CWpoint^ := CWpoint^ or (1 shl CWbit);
CWpoint^ := CWpoint^ or (cardinal(1) shl CWbit);
inc(src,2);
inc(o,2);
t := 0; // t=matchlen-2
@@ -4136,14 +4136,15 @@ class procedure TSynLog.DebuggerNotify(Level: TSynLogInfo;
FormatUTF8(Format,Args,Msg);
Add.LogInternal(Level,Msg,nil,maxInt);
{$ifdef MSWINDOWS}
{$ifndef FPC} // external exception :(
OutputDebugStringA(pointer(CurrentAnsiConvert.UTF8ToAnsi(Msg)));
{$endif}
{$ifdef LINUX}
{$endif FPC}
{$else}
{$I-}
write(Msg, ' ');
ioresult;
{$I+}
{$endif}
{$endif MSWINDOWS}
end;
{$ifndef FPC_OR_PUREPASCAL}
if DebugHook<>0 then
@@ -1 +1 @@
'1.18.4779'
'1.18.4780'

0 comments on commit c6ba9fc

Please sign in to comment.