Commit 4843b130 authored by Russ Cox's avatar Russ Cox

runtime: avoid allocation for fixed strings

R=r
CC=golang-dev
https://golang.org/cl/1083041
parent d6b199ac
......@@ -30,7 +30,7 @@ signame(int32 sig)
{
if(sig < 0 || sig >= NSIG)
return emptystring;
return gostring((byte*)sigtab[sig].name);
return gostringnocopy((byte*)sigtab[sig].name);
}
void
......
......@@ -38,7 +38,7 @@ signame(int32 sig)
{
if(sig < 0 || sig >= NSIG)
return emptystring;
return gostring((byte*)sigtab[sig].name);
return gostringnocopy((byte*)sigtab[sig].name);
}
void
......
......@@ -41,7 +41,7 @@ signame(int32 sig)
{
if(sig < 0 || sig >= NSIG)
return emptystring;
return gostring((byte*)sigtab[sig].name);
return gostringnocopy((byte*)sigtab[sig].name);
}
void
......
......@@ -49,7 +49,7 @@ signame(int32 sig)
{
if(sig < 0 || sig >= NSIG)
return emptystring;
return gostring((byte*)sigtab[sig].name);
return gostringnocopy((byte*)sigtab[sig].name);
}
void
......
......@@ -467,7 +467,7 @@ ifacehash1(void *data, Type *t)
if(algarray[alg].hash == nohash) {
// calling nohash will panic too,
// but we can print a better error.
·newErrorString(catstring(gostring((byte*)"hash of unhashable type "), *t->string), &err);
·newErrorString(catstring(gostringnocopy((byte*)"hash of unhashable type "), *t->string), &err);
·panic(err);
}
if(wid <= sizeof(data))
......@@ -501,7 +501,7 @@ ifaceeq1(void *data1, void *data2, Type *t)
if(algarray[alg].equal == noequal) {
// calling noequal will panic too,
// but we can print a better error.
·newErrorString(catstring(gostring((byte*)"comparing uncomparable type "), *t->string), &err);
·newErrorString(catstring(gostringnocopy((byte*)"comparing uncomparable type "), *t->string), &err);
·panic(err);
}
......
......@@ -38,7 +38,7 @@ signame(int32 sig)
{
if(sig < 0 || sig >= NSIG)
return emptystring;
return gostring((byte*)sigtab[sig].name);
return gostringnocopy((byte*)sigtab[sig].name);
}
void
......
......@@ -46,7 +46,7 @@ signame(int32 sig)
{
if(sig < 0 || sig >= NSIG)
return emptystring;
return gostring((byte*)sigtab[sig].name);
return gostringnocopy((byte*)sigtab[sig].name);
}
void
......
......@@ -46,7 +46,7 @@ signame(int32 sig)
{
if(sig < 0 || sig >= NSIG)
return emptystring;
return gostring((byte*)sigtab[sig].name);
return gostringnocopy((byte*)sigtab[sig].name);
}
void
......
......@@ -79,7 +79,7 @@ panicstring(int8 *s)
{
Eface err;
·newErrorString(gostring((byte*)s), &err);
·newErrorString(gostringnocopy((byte*)s), &err);
·panic(err);
}
......@@ -161,13 +161,13 @@ goargs(void)
genvv = malloc(envc*sizeof genvv[0]);
for(i=0; i<argc; i++)
gargv[i] = gostring(argv[i]);
gargv[i] = gostringnocopy(argv[i]);
os·Args.array = (byte*)gargv;
os·Args.len = argc;
os·Args.cap = argc;
for(i=0; i<envc; i++)
genvv[i] = gostring(argv[argc+1+i]);
genvv[i] = gostringnocopy(argv[argc+1+i]);
os·Envs.array = (byte*)genvv;
os·Envs.len = envc;
os·Envs.cap = envc;
......@@ -220,7 +220,7 @@ void
byte *p;
p = getenv("GOROOT");
out = gostring(p);
out = gostringnocopy(p);
FLUSH(&out);
}
......
......@@ -387,6 +387,7 @@ void* mal(uintptr);
uint32 cmpstring(String, String);
String catstring(String, String);
String gostring(byte*);
String gostringnocopy(byte*);
String gostringw(uint16*);
void initsig(void);
int32 gotraceback(void);
......
......@@ -60,6 +60,16 @@ gostring(byte *str)
return s;
}
String
gostringnocopy(byte *str)
{
String s;
s.str = str;
s.len = findnull(str);
return s;
}
String
gostringw(uint16 *str)
{
......
......@@ -106,7 +106,7 @@ dofunc(Sym *sym)
break;
}
f = &func[nfunc++];
f->name = gostring(sym->name);
f->name = gostringnocopy(sym->name);
f->entry = sym->value;
if(sym->symtype == 'L' || sym->symtype == 'l')
f->frame = -sizeof(uintptr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment