Skip to content

Commit 54fc650

Browse files
author
Brian Pane
committed
Additional speedup for apr_table_unset(): don't start doing the
check for dst_elt!=NULL on each iteration until we've seen the first instance of the target key git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@63580 13f79535-47bb-0310-9956-ffa450edef68
1 parent 10bb9e4 commit 54fc650

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

tables/apr_tables.c

+11-6
Original file line numberDiff line numberDiff line change
@@ -505,20 +505,25 @@ APR_DECLARE(void) apr_table_unset(apr_table_t *t, const char *key)
505505
{
506506
apr_table_entry_t *next_elt = (apr_table_entry_t *) t->a.elts;
507507
apr_table_entry_t *end_elt = next_elt + t->a.nelts;
508-
apr_table_entry_t *dst_elt = NULL;
508+
apr_table_entry_t *dst_elt;
509509
apr_uint32_t checksum;
510510

511511
COMPUTE_KEY_CHECKSUM(key, checksum);
512512
for (; next_elt < end_elt; next_elt++) {
513513
if ((checksum == next_elt->key_checksum) &&
514514
!strcasecmp(next_elt->key, key)) {
515515
t->a.nelts--;
516-
if (!dst_elt) {
517-
dst_elt = next_elt;
516+
dst_elt = next_elt;
517+
for (next_elt++; next_elt < end_elt; next_elt++) {
518+
if ((checksum == next_elt->key_checksum) &&
519+
!strcasecmp(next_elt->key, key)) {
520+
t->a.nelts--;
521+
}
522+
else {
523+
*dst_elt++ = *next_elt;
524+
}
518525
}
519-
}
520-
else if (dst_elt) {
521-
*dst_elt++ = *next_elt;
526+
break;
522527
}
523528
}
524529
}

0 commit comments

Comments
 (0)