Skip to content

Commit 315f87b

Browse files
committed
Remove unnecessary parameter from sorted array functions
1 parent 2eb0409 commit 315f87b

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

lib/src/array.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,23 @@ extern "C" {
8787

8888
#define _compare_int(a, b) ((int)*(a) - (int)(b))
8989

90-
#define array_search_sorted_by(self, start, field, needle, index, exists) \
91-
array__search_sorted(self, start, _compare_int, field, needle, index, exists)
90+
#define array_search_sorted_by(self, field, needle, index, exists) \
91+
array__search_sorted(self, 0, _compare_int, field, needle, index, exists)
9292

93-
#define array_search_sorted_with(self, start, compare, needle, index, exists) \
94-
array__search_sorted(self, start, compare, , needle, index, exists)
93+
#define array_search_sorted_with(self, compare, needle, index, exists) \
94+
array__search_sorted(self, 0, compare, , needle, index, exists)
9595

96-
#define array_insert_sorted_by(self, start, field, value) \
96+
#define array_insert_sorted_by(self, field, value) \
9797
do { \
9898
unsigned index, exists; \
99-
array_search_sorted_by(self, start, field, (value) field, &index, &exists); \
99+
array_search_sorted_by(self, field, (value) field, &index, &exists); \
100100
if (!exists) array_insert(self, index, value); \
101101
} while (0)
102102

103-
#define array_insert_sorted_with(self, start, compare, value) \
103+
#define array_insert_sorted_with(self, compare, value) \
104104
do { \
105105
unsigned index, exists; \
106-
array_search_sorted_with(self, start, compare, &(value), &index, &exists); \
106+
array_search_sorted_with(self, compare, &(value), &index, &exists); \
107107
if (!exists) array_insert(self, index, value); \
108108
} while (0)
109109

lib/src/query.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -764,12 +764,12 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) {
764764
uint32_t parent_step_index = parent_step_indices.contents[i];
765765
TSSymbol parent_symbol = self->steps.contents[parent_step_index].symbol;
766766
AnalysisSubgraph subgraph = { .symbol = parent_symbol };
767-
array_insert_sorted_by(&subgraphs, 0, .symbol, subgraph);
767+
array_insert_sorted_by(&subgraphs, .symbol, subgraph);
768768
}
769769
for (TSSymbol sym = self->language->token_count; sym < self->language->symbol_count; sym++) {
770770
if (!ts_language_symbol_metadata(self->language, sym).visible) {
771771
AnalysisSubgraph subgraph = { .symbol = sym };
772-
array_insert_sorted_by(&subgraphs, 0, .symbol, subgraph);
772+
array_insert_sorted_by(&subgraphs, .symbol, subgraph);
773773
}
774774
}
775775

@@ -798,7 +798,6 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) {
798798
for (const TSSymbol *symbol = aliases; symbol < aliases_end; symbol++) {
799799
array_search_sorted_by(
800800
&subgraphs,
801-
0,
802801
.symbol,
803802
*symbol,
804803
&subgraph_index,
@@ -833,7 +832,6 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) {
833832
for (const TSSymbol *symbol = aliases; symbol < aliases_end; symbol++) {
834833
array_search_sorted_by(
835834
&subgraphs,
836-
0,
837835
.symbol,
838836
*symbol,
839837
&subgraph_index,
@@ -882,8 +880,7 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) {
882880
};
883881
unsigned index, exists;
884882
array_search_sorted_with(
885-
&subgraph->nodes, 0,
886-
analysis_subgraph_node__compare, &predecessor_node,
883+
&subgraph->nodes, analysis_subgraph_node__compare, &predecessor_node,
887884
&index, &exists
888885
);
889886
if (!exists) {
@@ -930,7 +927,7 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) {
930927
uint16_t parent_depth = self->steps.contents[parent_step_index].depth;
931928
TSSymbol parent_symbol = self->steps.contents[parent_step_index].symbol;
932929
unsigned subgraph_index, exists;
933-
array_search_sorted_by(&subgraphs, 0, .symbol, parent_symbol, &subgraph_index, &exists);
930+
array_search_sorted_by(&subgraphs, .symbol, parent_symbol, &subgraph_index, &exists);
934931
if (!exists) continue;
935932
AnalysisSubgraph *subgraph = &subgraphs.contents[subgraph_index];
936933

@@ -996,7 +993,7 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) {
996993
if (next_states.size > 0) {
997994
int comparison = analysis_state__compare_position(state, array_back(&next_states));
998995
if (comparison == 0) {
999-
array_insert_sorted_with(&next_states, 0, analysis_state__compare, *state);
996+
array_insert_sorted_with(&next_states, analysis_state__compare, *state);
1000997
continue;
1001998
} else if (comparison > 0) {
1002999
while (j < states.size) {
@@ -1014,7 +1011,7 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) {
10141011
const QueryStep * const step = &self->steps.contents[state->step_index];
10151012

10161013
unsigned subgraph_index, exists;
1017-
array_search_sorted_by(&subgraphs, 0, .symbol, parent_symbol, &subgraph_index, &exists);
1014+
array_search_sorted_by(&subgraphs, .symbol, parent_symbol, &subgraph_index, &exists);
10181015
if (!exists) continue;
10191016
const AnalysisSubgraph *subgraph = &subgraphs.contents[subgraph_index];
10201017

@@ -1044,7 +1041,7 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) {
10441041
};
10451042
unsigned node_index;
10461043
array_search_sorted_with(
1047-
&subgraph->nodes, 0,
1044+
&subgraph->nodes,
10481045
analysis_subgraph_node__compare, &successor,
10491046
&node_index, &exists
10501047
);
@@ -1132,9 +1129,9 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) {
11321129
bool did_finish_pattern = self->steps.contents[next_state.step_index].depth != parent_depth + 1;
11331130
if (did_finish_pattern) can_finish_pattern = true;
11341131
if (next_state.depth > 0 && !did_finish_pattern) {
1135-
array_insert_sorted_with(&next_states, 0, analysis_state__compare, next_state);
1132+
array_insert_sorted_with(&next_states, analysis_state__compare, next_state);
11361133
} else {
1137-
array_insert_sorted_by(&final_step_indices, 0, , next_state.step_index);
1134+
array_insert_sorted_by(&final_step_indices, , next_state.step_index);
11381135
}
11391136
}
11401137

@@ -1180,7 +1177,7 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) {
11801177
assert(final_step_indices.size > 0);
11811178
uint16_t *impossible_step_index = array_back(&final_step_indices);
11821179
uint32_t i, exists;
1183-
array_search_sorted_by(&self->step_offsets, 0, .step_index, *impossible_step_index, &i, &exists);
1180+
array_search_sorted_by(&self->step_offsets, .step_index, *impossible_step_index, &i, &exists);
11841181
assert(exists);
11851182
*error_offset = self->step_offsets.contents[i].byte_offset;
11861183
result = false;
@@ -1201,7 +1198,7 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) {
12011198
) {
12021199
TSQueryPredicateStep *step = &self->predicate_steps.contents[j];
12031200
if (step->type == TSQueryPredicateStepTypeCapture) {
1204-
array_insert_sorted_by(&predicate_capture_ids, 0, , step->value_id);
1201+
array_insert_sorted_by(&predicate_capture_ids, , step->value_id);
12051202
}
12061203
}
12071204

@@ -1216,7 +1213,7 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) {
12161213
uint16_t capture_id = step->capture_ids[k];
12171214
if (capture_id == NONE) break;
12181215
unsigned index, exists;
1219-
array_search_sorted_by(&predicate_capture_ids, 0, , capture_id, &index, &exists);
1216+
array_search_sorted_by(&predicate_capture_ids, , capture_id, &index, &exists);
12201217
if (exists) {
12211218
step->is_definite = false;
12221219
break;

0 commit comments

Comments
 (0)