A bit speedup: in _rtld_load_object(), save the number of calls to

strcmp() by performing path name length comparison first. In the test
with Mozilla, the number was reduced to 1068 from 7182 (yes, we saved
6114 strcmp()!).
This commit is contained in:
junyoung 2002-12-05 04:56:56 +00:00
parent e578f0eb06
commit fd1f5e8f1b
4 changed files with 12 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: load.c,v 1.24 2002/10/05 11:59:04 mycroft Exp $ */
/* $NetBSD: load.c,v 1.25 2002/12/05 04:56:56 junyoung Exp $ */
/*
* Copyright 1996 John D. Polstra.
@ -105,10 +105,11 @@ _rtld_load_object(filepath, mode)
Obj_Entry *obj;
int fd = -1;
struct stat sb;
size_t pathlen = strlen(filepath);
for (obj = _rtld_objlist->next; obj != NULL; obj = obj->next)
if (!strcmp(obj->path, filepath))
break;
for (obj = _rtld_objlist->next; obj != NULL; obj = obj->next)
if (pathlen == obj->pathlen && !strcmp(obj->path, filepath))
break;
/*
* If we didn't find a match by pathname, open the file and check

View File

@ -1,4 +1,4 @@
/* $NetBSD: map_object.c,v 1.24 2002/10/05 11:59:04 mycroft Exp $ */
/* $NetBSD: map_object.c,v 1.25 2002/12/05 04:56:57 junyoung Exp $ */
/*
* Copyright 1996 John D. Polstra.
@ -87,6 +87,7 @@ _rtld_map_object(path, fd, sb)
obj = _rtld_obj_new();
obj->path = path;
obj->pathlen = strlen(path);
if (sb != NULL) {
obj->dev = sb->st_dev;
obj->ino = sb->st_ino;

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtld.c,v 1.88 2002/11/24 18:13:30 fvdl Exp $ */
/* $NetBSD: rtld.c,v 1.89 2002/12/05 04:56:57 junyoung Exp $ */
/*
* Copyright 1996 John D. Polstra.
@ -141,6 +141,7 @@ _rtld_init(mapbase, relocbase)
{
/* Conjure up an Obj_Entry structure for the dynamic linker. */
_rtld_objself.path = _rtld_path;
_rtld_objself.pathlen = strlen(_rtld_path);
_rtld_objself.rtld = true;
_rtld_objself.mapbase = mapbase;
_rtld_objself.relocbase = relocbase;
@ -360,6 +361,7 @@ _rtld(sp, relocbase)
_rtld_objmain = _rtld_digest_phdr(phdr, phnum, entry);
_rtld_objmain->path = xstrdup(argv[0] ? argv[0] :
"main program");
_rtld_objmain->pathlen = strlen(_rtld_objmain->path);
}
_rtld_objmain->mainprog = true;

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtld.h,v 1.64 2002/11/14 20:11:48 nathanw Exp $ */
/* $NetBSD: rtld.h,v 1.65 2002/12/05 04:56:57 junyoung Exp $ */
/*
* Copyright 1996 John D. Polstra.
@ -135,7 +135,7 @@ typedef struct Struct_Obj_Entry {
Elf_Dyn *dynamic; /* Dynamic section */
caddr_t entry; /* Entry point */
const Elf_Phdr *__junk001;
size_t __junk002;
size_t pathlen; /* Pathname length */
/* Items from the dynamic section. */
Elf_Addr *pltgot; /* PLTGOT table */