Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(240)

Unified Diff: src/cmd/gc/range.c

Issue 1680048: code review 1680048: gc: implement new len spec, range bug fix, optimization (Closed)
Patch Set: code review 1680048: gc: implement new len spec, range bug fix, optimization Created 14 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/cmd/gc/typecheck.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/cmd/gc/range.c
===================================================================
--- a/src/cmd/gc/range.c
+++ b/src/cmd/gc/range.c
@@ -24,6 +24,8 @@
typecheck(&n->right, Erv);
if((t = n->right->type) == T)
goto out;
+ if(isptr[t->etype] && isfixedarray(t->type))
+ t = t->type;
n->type = t;
switch(t->etype) {
@@ -104,9 +106,6 @@
a = nod(OCONV, n->right, N);
a->type = types[TSTRING];
}
- ha = nod(OXXX, N, N);
- tempname(ha, a->type);
- init = list(init, nod(OAS, ha, a));
v1 = n->list->n;
hv1 = N;
@@ -116,6 +115,16 @@
v2 = n->list->next->n;
hv2 = N;
+ if(v2 == N && t->etype == TARRAY) {
+ // will have just one reference to argument.
+ // no need to make a potentially expensive copy.
+ ha = a;
+ } else {
+ ha = nod(OXXX, N, N);
+ tempname(ha, a->type);
+ init = list(init, nod(OAS, ha, a));
+ }
+
switch(t->etype) {
default:
fatal("walkrange");
@@ -131,7 +140,7 @@
init = list(init, nod(OAS, hn, nod(OLEN, ha, N)));
if(v2) {
hp = nod(OXXX, N, N);
- tempname(hp, ptrto(a->type->type));
+ tempname(hp, ptrto(n->type->type));
tmp = nod(OINDEX, ha, nodintconst(0));
tmp->etype = 1; // no bounds check
init = list(init, nod(OAS, hp, nod(OADDR, tmp, N)));
« no previous file with comments | « no previous file | src/cmd/gc/typecheck.c » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b