Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure FastNewRawUTF8(var s: RawUTF8; len: integer);
- {$ifdef FPC} inline;
- begin
- SetString(s,nil,len);
- end;
- {$else}
- {$ifdef PUREPASCAL} {$ifdef HASINLINE}inline;{$endif}
- begin
- if len<>0 then
- if (PtrUInt(s)=0) or // s=''
- (PInteger(PtrUInt(s)-8)^<>1) or // s.refcount<>1
- (PInteger(PtrUInt(s)-4)^<>len) then // s.length<>len
- SetString(s,nil,len) else
- exit else
- if s='' then
- exit else
- s := '';
- end;
- {$else}
- asm // eax=s edx=len
- test edx,edx
- mov ecx,[eax]
- jz System.@LStrClr
- test ecx,ecx
- jz @set
- cmp dword ptr [ecx-8],1
- jne @set
- cmp dword ptr [ecx-4],edx
- je @out
- @set:mov ecx,edx
- xor edx,edx
- {$ifdef UNICODE}
- push CP_UTF8 // UTF-8 code page for Delphi 2009+
- call System.@LStrFromPCharLen // we need a call, not a jmp here
- {$else}
- jmp System.@LStrFromPCharLen
- {$endif}
- @out:
- end;
- {$endif PUREPASCAL}
- {$endif FPC}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement