Streamline alpm_splitdep() comparisons
This reduces from 5 to 3 the number of searches needed on the string looking for a comparison operator, since we can so a second quick comparison looking for '=' if we find '<' or '>'. It also makes every search doable with strchr() or memchr() rather than the slower strstr() method. In testing, only 10% of splitdep calls (~1600 / 16000) during an -Ss database load found a version comparison operator, so optimizing the not found path to be require less work makes sense. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
b3c0ae5205
commit
499e09734b
1 changed files with 19 additions and 13 deletions
|
@ -410,31 +410,37 @@ alpm_depend_t *_alpm_splitdep(const char *depstring)
|
||||||
{
|
{
|
||||||
alpm_depend_t *depend;
|
alpm_depend_t *depend;
|
||||||
const char *ptr, *version = NULL;
|
const char *ptr, *version = NULL;
|
||||||
|
size_t deplen;
|
||||||
|
|
||||||
if(depstring == NULL) {
|
if(depstring == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CALLOC(depend, 1, sizeof(alpm_depend_t), return NULL);
|
CALLOC(depend, 1, sizeof(alpm_depend_t), return NULL);
|
||||||
|
deplen = strlen(depstring);
|
||||||
|
|
||||||
/* Find a version comparator if one exists. If it does, set the type and
|
/* Find a version comparator if one exists. If it does, set the type and
|
||||||
* increment the ptr accordingly so we can copy the right strings. */
|
* increment the ptr accordingly so we can copy the right strings. */
|
||||||
if((ptr = strstr(depstring, ">="))) {
|
if((ptr = memchr(depstring, '<', deplen))) {
|
||||||
depend->mod = ALPM_DEP_MOD_GE;
|
if(ptr[1] == '=') {
|
||||||
version = ptr + 2;
|
|
||||||
} else if((ptr = strstr(depstring, "<="))) {
|
|
||||||
depend->mod = ALPM_DEP_MOD_LE;
|
depend->mod = ALPM_DEP_MOD_LE;
|
||||||
version = ptr + 2;
|
version = ptr + 2;
|
||||||
} else if((ptr = strstr(depstring, "="))) {
|
} else {
|
||||||
/* Note: we must do =,<,> checks after <=, >= checks */
|
|
||||||
depend->mod = ALPM_DEP_MOD_EQ;
|
|
||||||
version = ptr + 1;
|
|
||||||
} else if((ptr = strstr(depstring, "<"))) {
|
|
||||||
depend->mod = ALPM_DEP_MOD_LT;
|
depend->mod = ALPM_DEP_MOD_LT;
|
||||||
version = ptr + 1;
|
version = ptr + 1;
|
||||||
} else if((ptr = strstr(depstring, ">"))) {
|
}
|
||||||
|
} else if((ptr = memchr(depstring, '>', deplen))) {
|
||||||
|
if(ptr[1] == '=') {
|
||||||
|
depend->mod = ALPM_DEP_MOD_GE;
|
||||||
|
version = ptr + 2;
|
||||||
|
} else {
|
||||||
depend->mod = ALPM_DEP_MOD_GT;
|
depend->mod = ALPM_DEP_MOD_GT;
|
||||||
version = ptr + 1;
|
version = ptr + 1;
|
||||||
|
}
|
||||||
|
} else if((ptr = memchr(depstring, '=', deplen))) {
|
||||||
|
/* Note: we must do =,<,> checks after <=, >= checks */
|
||||||
|
depend->mod = ALPM_DEP_MOD_EQ;
|
||||||
|
version = ptr + 1;
|
||||||
} else {
|
} else {
|
||||||
/* no version specified, leave version and ptr NULL */
|
/* no version specified, leave version and ptr NULL */
|
||||||
depend->mod = ALPM_DEP_MOD_ANY;
|
depend->mod = ALPM_DEP_MOD_ANY;
|
||||||
|
|
Loading…
Add table
Reference in a new issue