allow access to injected item while creating filter text

This commit is contained in:
Pascal Kuthe
2024-04-02 02:31:13 +02:00
parent 2ca3e10350
commit a82a24999b
5 changed files with 13 additions and 6 deletions

View File

@@ -1,5 +1,12 @@
# Changelog
# [0.5.0] - 2024-4-2
## **Breaking Changes**
* `Injector::push` now passes a reference to the push value to the closure generating the columns
# [0.4.1] - 2024-3-11
## Bugfixes

2
Cargo.lock generated
View File

@@ -152,7 +152,7 @@ dependencies = [
[[package]]
name = "nucleo"
version = "0.4.0"
version = "0.4.1"
dependencies = [
"nucleo-matcher",
"parking_lot",

View File

@@ -2,7 +2,7 @@
name = "nucleo"
description = "plug and play high performance fuzzy matcher"
authors = ["Pascal Kuthe <pascalkuthe@pm.me>"]
version = "0.4.1"
version = "0.5.0"
edition = "2021"
license = "MPL-2.0"
repository = "https://github.com/helix-editor/nucleo"

View File

@@ -137,7 +137,7 @@ impl<T> Vec<T> {
}
/// Appends an element to the back of the vector.
pub fn push(&self, value: T, fill_columns: impl FnOnce(&mut [Utf32String])) -> u32 {
pub fn push(&self, value: T, fill_columns: impl FnOnce(&T, &mut [Utf32String])) -> u32 {
let index = self.inflight.fetch_add(1, Ordering::Release);
// the inflight counter is a `u64` to catch overflows of the vector'scapacity
let index: u32 = index.try_into().expect("overflowed maximum capacity");
@@ -170,11 +170,11 @@ impl<T> Vec<T> {
//
// 2. any thread trying to `get` this entry will see `active == false`,
// and will not try to access it
(*entry).slot.get().write(MaybeUninit::new(value));
for col in Entry::matcher_cols_raw(entry, self.columns) {
col.get().write(MaybeUninit::new(Utf32String::default()))
}
fill_columns(Entry::matcher_cols_mut(entry, self.columns));
fill_columns(&value, Entry::matcher_cols_mut(entry, self.columns));
(*entry).slot.get().write(MaybeUninit::new(value));
// let other threads know that this entry is active
(*entry).active.store(true, Ordering::Release);
}

View File

@@ -73,7 +73,7 @@ impl<T> Clone for Injector<T> {
impl<T> Injector<T> {
/// Appends an element to the list of matched items.
/// This function is lock-free and wait-free.
pub fn push(&self, value: T, fill_columns: impl FnOnce(&mut [Utf32String])) -> u32 {
pub fn push(&self, value: T, fill_columns: impl FnOnce(&T, &mut [Utf32String])) -> u32 {
let idx = self.items.push(value, fill_columns);
(self.notify)();
idx