mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-13 10:59:18 +02:00
Optimized the comparison of a widestring variable with ''
This commit is contained in:
parent
35db2b2da3
commit
60c967f255
@ -3290,7 +3290,7 @@ implementation
|
|||||||
var
|
var
|
||||||
p: tnode;
|
p: tnode;
|
||||||
newstatement : tstatementnode;
|
newstatement : tstatementnode;
|
||||||
tempnode (*,tempnode2*) : ttempcreatenode;
|
tempnode : ttempcreatenode;
|
||||||
cmpfuncname: string;
|
cmpfuncname: string;
|
||||||
para: tcallparanode;
|
para: tcallparanode;
|
||||||
begin
|
begin
|
||||||
@ -3399,8 +3399,6 @@ implementation
|
|||||||
{ generate better code for comparison with empty string, we
|
{ generate better code for comparison with empty string, we
|
||||||
only need to compare the length with 0 }
|
only need to compare the length with 0 }
|
||||||
if (nodetype in [equaln,unequaln,gtn,gten,ltn,lten]) and
|
if (nodetype in [equaln,unequaln,gtn,gten,ltn,lten]) and
|
||||||
{ windows widestrings are too complicated to be handled optimized }
|
|
||||||
not(is_widestring(left.resultdef) and (target_info.system in systems_windows)) and
|
|
||||||
(((left.nodetype=stringconstn) and (tstringconstnode(left).len=0)) or
|
(((left.nodetype=stringconstn) and (tstringconstnode(left).len=0)) or
|
||||||
((right.nodetype=stringconstn) and (tstringconstnode(right).len=0))) then
|
((right.nodetype=stringconstn) and (tstringconstnode(right).len=0))) then
|
||||||
begin
|
begin
|
||||||
@ -3419,40 +3417,18 @@ implementation
|
|||||||
result := caddnode.create(nodetype,
|
result := caddnode.create(nodetype,
|
||||||
cinlinenode.create(in_length_x,false,left),
|
cinlinenode.create(in_length_x,false,left),
|
||||||
cordconstnode.create(0,s8inttype,false))
|
cordconstnode.create(0,s8inttype,false))
|
||||||
else
|
else { nodetype in [equaln,unequaln] }
|
||||||
begin
|
begin
|
||||||
(*
|
if is_widestring(left.resultdef) and (tf_winlikewidestring in target_info.flags) then
|
||||||
if is_widestring(left.resultdef) and
|
|
||||||
(target_info.system in system_windows) then
|
|
||||||
begin
|
begin
|
||||||
{ windows like widestrings requires that we also check the length }
|
{ windows like widestrings requires that we also check the length }
|
||||||
result:=internalstatements(newstatement);
|
result:=cinlinenode.create(in_length_x,false,left);
|
||||||
tempnode:=ctempcreatenode.create(voidpointertype,voidpointertype.size,tt_persistent,true);
|
{ and compare its result with 0 }
|
||||||
tempnode2:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,true);
|
result:=caddnode.create(equaln,result,cordconstnode.create(0,s8inttype,false));
|
||||||
addstatement(newstatement,tempnode);
|
if nodetype=unequaln then
|
||||||
addstatement(newstatement,tempnode2);
|
result:=cnotnode.create(result);
|
||||||
{ poor man's cse }
|
|
||||||
addstatement(newstatement,cassignmentnode.create(ctemprefnode.create(tempnode),
|
|
||||||
ctypeconvnode.create_internal(left,voidpointertype))
|
|
||||||
);
|
|
||||||
addstatement(newstatement,cassignmentnode.create(ctemprefnode.create(tempnode2),
|
|
||||||
caddnode.create(orn,
|
|
||||||
caddnode.create(nodetype,
|
|
||||||
ctemprefnode.create(tempnode),
|
|
||||||
cpointerconstnode.create(0,voidpointertype)
|
|
||||||
),
|
|
||||||
caddnode.create(nodetype,
|
|
||||||
ctypeconvnode.create_internal(cderefnode.create(ctemprefnode.create(tempnode)),s32inttype),
|
|
||||||
cordconstnode.create(0,s32inttype,false)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
));
|
|
||||||
addstatement(newstatement,ctempdeletenode.create_normal_temp(tempnode));
|
|
||||||
addstatement(newstatement,ctempdeletenode.create_normal_temp(tempnode2));
|
|
||||||
addstatement(newstatement,ctemprefnode.create(tempnode2));
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
*)
|
|
||||||
begin
|
begin
|
||||||
{ compare the pointer with nil (for ansistrings etc), }
|
{ compare the pointer with nil (for ansistrings etc), }
|
||||||
{ faster than getting the length (JM) }
|
{ faster than getting the length (JM) }
|
||||||
|
Loading…
Reference in New Issue
Block a user