-
function Format(const Fmt: string; const Args: array of const): string;
asm
PUSH ESI
PUSH EDI
PUSH EBX
MOV EBX, ESP
ADD ESP, -2048
MOV ESI, ESP
INC ECX
JZ @@2
@@1:
MOV EDI, [EDX + ECX*8 - 8]
PUSH EDI
LOOP @@1
@@2:
PUSH ESP
PUSH EAX
PUSH ESI
CALL wvsprintf
MOV EDX, ESI
MOV ECX, EAX // by Freeman
MOV EAX, @Result
CALL System.@LStrFromPCharLen // by Freeman, performance hit
MOV ESP, EBX
POP EBX
POP EDI
POP ESI
end; -
Thaddy (14.07.08 11:48) [1]Not really strange:
I suppose you are using the unicode version of wvsprintf?
In that case you should call LStrFromPWCharLen.
Otherwise you get a performance hit because the unicodestring gets converted to string in the background by the OS.
Also it is a good idea to use kolstring instead of string. -
He-he. In my project (not KOL-based) I'm using these snippets:function FormatBuf(Fmt: PAnsiChar; Args: array of const; Buf: PAnsiChar): Integer;
asm
PUSH EDI
INC ECX
JZ @@2
@@1:
MOV EDI, [EDX + ECX*8 - 8]
PUSH EDI
LOOP @@1
@@2:
PUSH ESP
PUSH EAX
MOV EDI, Buf
PUSH EDI
CALL wvsprintfA
POP EDI
end;
function WideFormatBuf(Fmt: PWideChar; Args: array of const; Buf: PWideChar): Integer;
asm
PUSH EDI
INC ECX
JZ @@2
@@1:
MOV EDI, [EDX + ECX*8 - 8]
PUSH EDI
LOOP @@1
@@2:
PUSH ESP
PUSH EAX
MOV EDI, Buf
PUSH EDI
CALL wvsprintfW
POP EDI
end; -
Thaddy (21.07.08 17:38) [3]This would be a start to work with kol strings.
function FormatBuf(Fmt: PAnsiChar; Args: array of const; Buf: PAnsiChar): Integer;overload;
asm
PUSH EDI
INC ECX
JZ @@2
@@1:
MOV EDI, [EDX + ECX*8 - 8]
PUSH EDI
LOOP @@1
@@2:
PUSH ESP
PUSH EAX
MOV EDI, Buf
PUSH EDI
CALL wvsprintfA
POP EDI
end;
function FormatBuf(Fmt: PWideChar; Args: array of const; Buf: PWideChar): Integer;overload;
asm
PUSH EDI
INC ECX
JZ @@2
@@1:
MOV EDI, [EDX + ECX*8 - 8]
PUSH EDI
LOOP @@1
@@2:
PUSH ESP
PUSH EAX
MOV EDI, Buf
PUSH EDI
CALL wvsprintfW
POP EDI
end;