@@ -85204,22 +85204,14 @@ bool flecs_query_apply_or_mask(
8520485204 const ecs_query_t *query,
8520585205 ecs_table_t *table,
8520685206 int32_t block_index,
85207- int32_t field_index ,
85207+ int32_t term_index ,
8520885208 ecs_flags64_t *mask,
8520985209 bool *has_bitset)
8521085210{
85211- /* Find first term for field index. Terms in an OR chain share the
85212- * same field index, so this finds the start of the chain. */
85213- int32_t i = field_index, term_count = query->term_count;
8521485211 ecs_term_t *terms = query->terms;
85212+ int32_t i = term_index;
8521585213
85216- for (; i < term_count; i ++) {
85217- if (terms[i].field_index == field_index) {
85218- break;
85219- }
85220- }
85221-
85222- if (i == term_count || terms[i].oper != EcsOr) {
85214+ if (terms[i].oper != EcsOr) {
8522385215 return false;
8522485216 }
8522585217
@@ -85260,12 +85252,24 @@ flecs_query_row_mask_t flecs_query_get_row_mask(
8526085252 ecs_query_toggle_ctx_t *op_ctx)
8526185253{
8526285254 ecs_flags64_t mask = UINT64_MAX;
85263- int32_t i, field_count = it->field_count;
85264- ecs_flags64_t fields = and_fields | not_fields;
85255+ int32_t i;
85256+ const ecs_flags64_t fields = and_fields | not_fields;
85257+ int32_t term_index = 0;
85258+ const int32_t term_count = query->term_count;
85259+ const ecs_term_t *terms = query->terms;
8526585260 bool has_bitset = false;
8526685261
85267- for (i = 0; i < field_count; i ++) {
85268- uint64_t field_bit = 1llu << i;
85262+ for (i = 0; i < it->field_count; i ++) {
85263+ const uint64_t field_bit = 1llu << i;
85264+
85265+ ecs_assert(term_index < term_count, ECS_INTERNAL_ERROR, NULL);
85266+ ecs_assert(terms[term_index].field_index == i, ECS_INTERNAL_ERROR, NULL);
85267+
85268+ const int32_t field_term_index = term_index;
85269+ do {
85270+ term_index ++;
85271+ } while ((term_index < term_count) && (terms[term_index].field_index == i));
85272+
8526985273 if (!(fields & field_bit)) {
8527085274 continue;
8527185275 }
@@ -85278,7 +85282,9 @@ flecs_query_row_mask_t flecs_query_get_row_mask(
8527885282 ecs_abort(ECS_INTERNAL_ERROR, NULL);
8527985283 }
8528085284
85281- if (flecs_query_apply_or_mask(query, table, block_index, i, &mask, &has_bitset)) {
85285+ if (flecs_query_apply_or_mask(query, table, block_index,
85286+ field_term_index, &mask, &has_bitset))
85287+ {
8528285288 continue;
8528385289 }
8528485290
@@ -85317,7 +85323,7 @@ bool flecs_query_toggle_for_up(
8531785323 ecs_flags64_t fields = (and_fields | not_fields) & it->up_fields;
8531885324
8531985325 for (i = 0; i < field_count; i ++) {
85320- uint64_t field_bit = 1llu << i;
85326+ const uint64_t field_bit = 1llu << i;
8532185327 if (!(fields & field_bit)) {
8532285328 continue;
8532385329 }
0 commit comments