mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2025-03-11 17:08:46 +00:00
Replace for loops with memcpy
This commit is contained in:
parent
c5ff98e57b
commit
7ad8a4cfe1
@ -398,22 +398,16 @@ compute_buckets_intersection(struct trie_node *node, const struct trie_node *lef
|
|||||||
assert(right != NULL);
|
assert(right != NULL);
|
||||||
assert(node != NULL);
|
assert(node != NULL);
|
||||||
|
|
||||||
struct aggregator_bucket *fst[64] = { 0 };
|
struct aggregator_bucket *fst[MAX_POTENTIAL_BUCKETS_COUNT] = { 0 };
|
||||||
struct aggregator_bucket *snd[64] = { 0 };
|
struct aggregator_bucket *snd[MAX_POTENTIAL_BUCKETS_COUNT] = { 0 };
|
||||||
|
|
||||||
int fst_count = 0;
|
memcpy(fst, left->potential_buckets, sizeof(left->potential_buckets[0]) * left->potential_buckets_count);
|
||||||
int snd_count = 0;
|
memcpy(snd, right->potential_buckets, sizeof(right->potential_buckets[0]) * right->potential_buckets_count);
|
||||||
|
|
||||||
for (int i = 0; i < left->potential_buckets_count; i++)
|
qsort(fst, left->potential_buckets_count, sizeof(fst[0]), aggregator_bucket_compare_wrapper);
|
||||||
fst[fst_count++] = left->potential_buckets[i];
|
qsort(snd, right->potential_buckets_count, sizeof(snd[0]), aggregator_bucket_compare_wrapper);
|
||||||
|
|
||||||
for (int i = 0; i < right->potential_buckets_count; i++)
|
struct aggregator_bucket *output[MAX_POTENTIAL_BUCKETS_COUNT * 2] = { 0 };
|
||||||
snd[snd_count++] = right->potential_buckets[i];
|
|
||||||
|
|
||||||
qsort(fst, fst_count, sizeof(struct aggregator_bucket *), aggregator_bucket_compare_wrapper);
|
|
||||||
qsort(snd, snd_count, sizeof(struct aggregator_bucket *), aggregator_bucket_compare_wrapper);
|
|
||||||
|
|
||||||
struct aggregator_bucket *output[64] = { 0 };
|
|
||||||
int output_count = 0;
|
int output_count = 0;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -421,11 +415,11 @@ compute_buckets_intersection(struct trie_node *node, const struct trie_node *lef
|
|||||||
|
|
||||||
while (i < left->potential_buckets_count && j < right->potential_buckets_count)
|
while (i < left->potential_buckets_count && j < right->potential_buckets_count)
|
||||||
{
|
{
|
||||||
int res = aggregator_bucket_compare(left->potential_buckets[i], right->potential_buckets[j]);
|
int res = aggregator_bucket_compare(fst[i], snd[j]);
|
||||||
|
|
||||||
if (res == 0)
|
if (res == 0)
|
||||||
{
|
{
|
||||||
output[output_count++] = left->potential_buckets[i];
|
output[output_count++] = fst[i];
|
||||||
i++;
|
i++;
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
@ -446,13 +440,8 @@ compute_buckets_intersection(struct trie_node *node, const struct trie_node *lef
|
|||||||
for (int l = k + 1; l < output_count; l++)
|
for (int l = k + 1; l < output_count; l++)
|
||||||
assert(output[k] != output[l]);
|
assert(output[k] != output[l]);
|
||||||
|
|
||||||
for (int k = 0; k < output_count; k++)
|
node->potential_buckets_count = output_count < MAX_POTENTIAL_BUCKETS_COUNT ? output_count : MAX_POTENTIAL_BUCKETS_COUNT;
|
||||||
{
|
memcpy(node->potential_buckets, output, sizeof(node->potential_buckets[0]) * node->potential_buckets_count);
|
||||||
if (node->potential_buckets_count >= MAX_POTENTIAL_BUCKETS_COUNT)
|
|
||||||
break;
|
|
||||||
|
|
||||||
node->potential_buckets[node->potential_buckets_count++] = output[k];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user