Skip to content

Commit d6928e2

Browse files
authored
Merge pull request #78 from atom-community/bug-fix
2 parents a9043c5 + facdd71 commit d6928e2

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/TreeFilterer.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class TreeFilterer {
5656

5757

5858
if (keepReference) {
59+
if (candidates_view != nullptr) {
60+
// release the already kept reference
61+
candidates_view.Unref();
62+
}
5963
// store a view of candidates in case filter was called
6064
candidates_view = get_ref<ReferenceType, ArrayType>(candidates_);
6165
}
@@ -135,10 +139,19 @@ class TreeFilterer {
135139
if (i_parent_index < parent_indices_len) {
136140
const auto parent_index = parent_indices[i_parent_index];
137141
// for each parent index get the original object at that index
142+
// BUG this check shouldn't be required
143+
if (parent_index >= get_size(temp_children)) {
144+
continue;
145+
}
146+
assert(parent_index < get_size(temp_children));
138147
temp_parent = get_at<ArrayType, NodeType>(temp_children, parent_index);
139148
// update the children for the next iteration
140149
temp_children = get_children<NodeType, ArrayType, AllocatorType>(temp_parent, children_key, env);
141150
} else {
151+
// BUG this check shouldn't be required
152+
if (index >= get_size(temp_children)) {
153+
continue;
154+
}
142155
assert(i_parent_index == parent_indices_len);
143156
assert(index < get_size(temp_children));
144157
// once parent indices finished, we get the index instead of the last parent

src/binding/binding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function validate_filterTree(...args: Parameters<Zadeh["filterIndicesTree
6767
}
6868

6969
export function validate_setTreeFiltererCandidates(...args: Parameters<Zadeh["setTreeFiltererCandidates"]>) {
70-
if (!Array.isArray(args[0])) {
70+
if (!(Array.isArray(args[0]) && typeof args[1] === "string" && typeof args[2] === "string")) {
7171
throw new Error(`Invalid arguments for setTreeFiltererCandidates: ${args}`)
7272
}
7373
}

src/binding/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ export class ObjectArrayFilterer<DataKey extends string | number = string> {
222222
const useExtensionBonus = Boolean(options.useExtensionBonus)
223223

224224
Binding.validate_filter(query, maxResult, usePathScoring, useExtensionBonus)
225+
if (query.length === 0) {
226+
// optimization for query === ""
227+
return []
228+
}
225229
// NOTE calling obj.filter is slower than (obj.filterIndices then map) due to the interop overhead
226230
return this.obj.filterIndices(query, maxResult, usePathScoring, useExtensionBonus)
227231
}
@@ -356,6 +360,10 @@ export class TreeFilterer<DataKey extends string = string, ChildrenKey extends s
356360
const useExtensionBonus = Boolean(options.useExtensionBonus)
357361

358362
Binding.validate_filterTree(query, maxResult, usePathScoring, useExtensionBonus)
363+
if (query.length === 0) {
364+
// optimization for query === ""
365+
return []
366+
}
359367
return this.obj.filterTree(query, maxResult, usePathScoring, useExtensionBonus)
360368
}
361369

@@ -369,6 +377,10 @@ export class TreeFilterer<DataKey extends string = string, ChildrenKey extends s
369377
*/
370378
filterIndices(query: string, options: TreeFilterOptions = {}): TreeFilterIndicesResult[] {
371379
parseOptions(options)
380+
if (query.length === 0) {
381+
// optimization for query === ""
382+
return []
383+
}
372384
return this.obj.filterIndicesTree(
373385
query,
374386
options.maxResults ?? 0,

0 commit comments

Comments
 (0)