mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-22 15:58:50 -05:00
Remove need for memory allocation in _alpm_depcmp
Noticed when tweaking testdb, when we run _alpm_depcmp in loops and call it seven million times, the strdup()/free() combo can add up. Remove the need for any string duplication by some pointer manipulation and use of strncmp instead of strcmp. Also kill the function logger and add an escape so we don't needlessly retrieve the list of provides. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
126f50ab0b
commit
34a78d935a
@ -322,9 +322,6 @@ static int dep_vercmp(const char *version1, pmdepmod_t mod,
|
||||
int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
|
||||
{
|
||||
alpm_list_t *i;
|
||||
|
||||
ALPM_LOG_FUNC;
|
||||
|
||||
const char *pkgname = alpm_pkg_get_name(pkg);
|
||||
const char *pkgversion = alpm_pkg_get_version(pkg);
|
||||
int satisfy = 0;
|
||||
@ -332,22 +329,29 @@ int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
|
||||
/* check (pkg->name, pkg->version) */
|
||||
satisfy = (strcmp(pkgname, dep->name) == 0
|
||||
&& dep_vercmp(pkgversion, dep->mod, dep->version));
|
||||
if(satisfy) {
|
||||
return(satisfy);
|
||||
}
|
||||
|
||||
/* check provisions, format : "name=version" */
|
||||
for(i = alpm_pkg_get_provides(pkg); i && !satisfy; i = i->next) {
|
||||
char *provname = strdup(i->data);
|
||||
char *provver = strchr(provname, '=');
|
||||
const char *provision = i->data;
|
||||
const char *provver = strchr(provision, '=');
|
||||
|
||||
if(provver == NULL) { /* no provision version */
|
||||
satisfy = (dep->mod == PM_DEP_MOD_ANY
|
||||
&& strcmp(provname, dep->name) == 0);
|
||||
&& strcmp(provision, dep->name) == 0);
|
||||
} else {
|
||||
*provver = '\0';
|
||||
/* This is a bit tricker than the old code for performance reasons. To
|
||||
* prevent the need to copy and duplicate strings, strncmp only the name
|
||||
* portion if they are the same length, since there is a version and
|
||||
* operator in play here. */
|
||||
size_t namelen = provver - provision;
|
||||
provver += 1;
|
||||
satisfy = (strcmp(provname, dep->name) == 0
|
||||
satisfy = (strlen(dep->name) == namelen
|
||||
&& strncmp(provision, dep->name, namelen) == 0
|
||||
&& dep_vercmp(provver, dep->mod, dep->version));
|
||||
}
|
||||
free(provname);
|
||||
}
|
||||
|
||||
return(satisfy);
|
||||
|
Loading…
Reference in New Issue
Block a user