Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
c9293f0c
Commit
c9293f0c
authored
Apr 11, 2010
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gc: compile s == "" as len(s) == 0
R=ken2 CC=golang-dev
https://golang.org/cl/840043
parent
9475cafa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
0 deletions
+24
-0
src/cmd/gc/walk.c
src/cmd/gc/walk.c
+24
-0
No files found.
src/cmd/gc/walk.c
View file @
c9293f0c
...
...
@@ -1053,6 +1053,30 @@ walkexpr(Node **np, NodeList **init)
goto
ret
;
case
OCMPSTR
:
// If one argument to the comparison is an empty string,
// comparing the lengths instead will yield the same result
// without the function call.
if
((
isconst
(
n
->
left
,
CTSTR
)
&&
n
->
left
->
val
.
u
.
sval
->
len
==
0
)
||
(
isconst
(
n
->
right
,
CTSTR
)
&&
n
->
right
->
val
.
u
.
sval
->
len
==
0
))
{
r
=
nod
(
n
->
etype
,
nod
(
OLEN
,
n
->
left
,
N
),
nod
(
OLEN
,
n
->
right
,
N
));
typecheck
(
&
r
,
Erv
);
walkexpr
(
&
r
,
init
);
n
=
r
;
goto
ret
;
}
// s + "badgerbadgerbadger" == "badgerbadgerbadger"
if
((
n
->
etype
==
OEQ
||
n
->
etype
==
ONE
)
&&
isconst
(
n
->
right
,
CTSTR
)
&&
n
->
left
->
op
==
OADDSTR
&&
isconst
(
n
->
left
->
right
,
CTSTR
)
&&
cmpslit
(
n
->
right
,
n
->
left
->
right
)
==
0
)
{
r
=
nod
(
n
->
etype
,
nod
(
OLEN
,
n
->
left
->
left
,
N
),
nodintconst
(
0
));
typecheck
(
&
r
,
Erv
);
walkexpr
(
&
r
,
init
);
n
=
r
;
goto
ret
;
}
// sys_cmpstring(s1, s2) :: 0
r
=
mkcall
(
"cmpstring"
,
types
[
TINT
],
init
,
conv
(
n
->
left
,
types
[
TSTRING
]),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment