header.c (dataLength): optimize string array loops

This commit is contained in:
Alexey Tourbin 2011-01-21 02:02:57 +03:00
parent dfd33329ab
commit 1c87e9b34f

View File

@ -346,29 +346,20 @@ static int dataLength(int_32 type, hPTR_t p, int_32 count, int onDisk)
case RPM_STRING_ARRAY_TYPE: case RPM_STRING_ARRAY_TYPE:
case RPM_I18NSTRING_TYPE: case RPM_I18NSTRING_TYPE:
{ int i;
/* This is like RPM_STRING_TYPE, except it's *always* an array */ /* This is like RPM_STRING_TYPE, except it's *always* an array */
/* Compute sum of length of all strings, including null terminators */ /* Compute sum of length of all strings, including null terminators */
i = count;
if (onDisk) { if (onDisk) {
const char * chptr = p; const char *end = p;
int thisLen; while (count--)
end += strlen(end) + 1;
while (i--) { length = end - (const char *) p;
thisLen = strlen(chptr) + 1;
length += thisLen;
chptr += thisLen;
}
} else { } else {
const char ** src = (const char **)p; const char **src = (const char **) p;
while (i--) { const char **end = src + count;
/* add one for null termination */ while (src < end)
length += strlen(*src++) + 1; length += strlen(*src++) + 1;
}
} }
} break; break;
default: default:
if (typeSizes[type] != -1) { if (typeSizes[type] != -1) {