1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-28 00:21:52 +03:00
2001-11-08  Ulrich Drepper  <drepper@redhat.com>

	* elf/dl-object.c (_dl_new_object): Various small optimizations.
This commit is contained in:
Ulrich Drepper
2001-11-08 22:32:38 +00:00
parent 40b07f5b94
commit 7bccbc05af
2 changed files with 51 additions and 47 deletions

View File

@ -1,3 +1,7 @@
2001-11-08 Ulrich Drepper <drepper@redhat.com>
* elf/dl-object.c (_dl_new_object): Various small optimizations.
2001-11-07 Ulrich Drepper <drepper@redhat.com> 2001-11-07 Ulrich Drepper <drepper@redhat.com>
* sysdeps/generic/dl-cache.c: Optimize SEARCH_CACHE and * sysdeps/generic/dl-cache.c: Optimize SEARCH_CACHE and

View File

@ -45,13 +45,12 @@ _dl_new_object (char *realname, const char *libname, int type,
if (new == NULL) if (new == NULL)
return NULL; return NULL;
newname = (struct libname_list *) (new + 1); new->l_libname = newname = (struct libname_list *) (new + 1);
newname->name = (char *) memcpy (newname + 1, libname, libname_len); newname->name = (char *) memcpy (newname + 1, libname, libname_len);
/* newname->next = NULL; We use calloc therefore not necessary. */ /* newname->next = NULL; We use calloc therefore not necessary. */
newname->dont_free = 1; newname->dont_free = 1;
new->l_name = realname; new->l_name = realname;
new->l_libname = newname;
new->l_type = type; new->l_type = type;
new->l_loader = loader; new->l_loader = loader;
/* new->l_global = 0; We use calloc therefore not necessary. */ /* new->l_global = 0; We use calloc therefore not necessary. */
@ -68,7 +67,7 @@ _dl_new_object (char *realname, const char *libname, int type,
if (_dl_loaded != NULL) if (_dl_loaded != NULL)
{ {
l = _dl_loaded; l = _dl_loaded;
while (l->l_next) while (l->l_next != NULL)
l = l->l_next; l = l->l_next;
new->l_prev = l; new->l_prev = l;
/* new->l_next = NULL; Would be necessary but we use calloc. */ /* new->l_next = NULL; Would be necessary but we use calloc. */
@ -80,82 +79,83 @@ _dl_new_object (char *realname, const char *libname, int type,
else else
_dl_loaded = new; _dl_loaded = new;
++_dl_nloaded; ++_dl_nloaded;
/* This is our local scope. */
if (loader != NULL) /* If we have no loader the new object acts as it. */
{ if (loader == NULL)
while (loader->l_loader != NULL) loader = new;
loader = loader->l_loader; else
if (idx == 0 || &loader->l_searchlist != new->l_scope[0]) /* Determine the local scope. */
new->l_scope[idx] = &loader->l_searchlist; while (loader->l_loader != NULL)
} loader = loader->l_loader;
else if (idx == 0 || &new->l_searchlist != new->l_scope[0])
new->l_scope[idx] = &new->l_searchlist; /* Insert the scope if it isn't the global scope we already added. */
if (idx == 0 || &loader->l_searchlist != new->l_scope[0])
new->l_scope[idx] = &loader->l_searchlist;
new->l_local_scope[0] = &new->l_searchlist; new->l_local_scope[0] = &new->l_searchlist;
/* Don't try to find the origin for the main map which has the name "". */ /* Don't try to find the origin for the main map which has the name "". */
if (realname[0] != '\0') if (realname[0] != '\0')
{ {
size_t realname_len = strlen (realname) + 1;
char *origin; char *origin;
char *cp;
if (realname[0] == '/') if (realname[0] == '/')
{ {
/* It an absolute path. Use it. But we have to make a copy since /* It is an absolute path. Use it. But we have to make a
we strip out the trailing slash. */ copy since we strip out the trailing slash. */
size_t len = strlen (realname) + 1; cp = origin = (char *) malloc (realname_len);
origin = (char *) malloc (len);
if (origin == NULL) if (origin == NULL)
origin = (char *) -1; {
else origin = (char *) -1;
memcpy (origin, realname, len); goto out;
}
} }
else else
{ {
size_t realname_len = strlen (realname) + 1; size_t len = realname_len;
size_t len = 128 + realname_len;
char *result = NULL; char *result = NULL;
/* Get the current directory name. */ /* Get the current directory name. */
origin = (char *) malloc (len); origin = NULL;
do
while (origin != NULL
&& (result = __getcwd (origin, len - realname_len)) == NULL
&& errno == ERANGE)
{ {
len += 128; len += 128;
origin = (char *) realloc (origin, len); origin = (char *) realloc (origin, len);
} }
while (origin != NULL
&& (result = __getcwd (origin, len - realname_len)) == NULL
&& errno == ERANGE);
if (result == NULL) if (result == NULL)
{ {
/* We were not able to determine the current directory. */ /* We were not able to determine the current directory.
Note that free(origin) is OK if origin == NULL. */
free (origin); free (origin);
origin = (char *) -1; origin = (char *) -1;
goto out;
} }
else
{
/* Now append the filename. */
char *cp = strchr (origin, '\0');
if (cp [-1] != '/') /* Find the end of the path and see whether we have to add
*cp++ = '/'; a slash. */
cp = __rawmemchr (origin, '\0');
memcpy (cp, realname, realname_len); if (cp[-1] != '/')
} *cp++ = '/';
} }
if (origin != (char *) -1) /* Add the real file name. */
{ memcpy (cp, realname, realname_len);
/* Now remove the filename and the slash. Do this even if the
string is something like "/foo" which leaves an empty string. */
char *last = strrchr (origin, '/');
if (last == origin) /* Now remove the filename and the slash. Leave the slash if it
origin[1] = '\0'; the name is something like "/foo". */
else cp = strrchr (origin, '/');
*last = '\0'; if (cp == origin)
} origin[1] = '\0';
else
*cp = '\0';
out:
new->l_origin = origin; new->l_origin = origin;
} }