1
0
mirror of https://github.com/golang/go synced 2024-11-25 13:57:57 -07:00

runtime: avoid allocation for fixed strings

R=r
CC=golang-dev
https://golang.org/cl/1083041
This commit is contained in:
Russ Cox 2010-05-19 21:33:31 -07:00
parent d6b199ac99
commit 4843b130bb
12 changed files with 25 additions and 14 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);
}

View File

@ -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);

View File

@ -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)
{

View File

@ -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);