Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix levenstein
  • Loading branch information
youknowone committed Jul 29, 2025
commit 95bf98e159174befd2c36623ec19d03c85d91a2f
4 changes: 2 additions & 2 deletions common/src/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ pub mod levenshtein {
if a == b { CASE_COST } else { MOVE_COST }
}

pub fn levenshtein_distance(a: &str, b: &str, max_cost: usize) -> usize {
pub fn levenshtein_distance(a: &[u8], b: &[u8], max_cost: usize) -> usize {
thread_local! {
#[allow(clippy::declare_interior_mutable_const)]
static BUFFER: RefCell<[usize; MAX_STRING_SIZE]> = const {
Expand All @@ -499,7 +499,7 @@ pub mod levenshtein {
return 0;
}

let (mut a_bytes, mut b_bytes) = (a.as_bytes(), b.as_bytes());
let (mut a_bytes, mut b_bytes) = (a, b);
let (mut a_begin, mut a_end) = (0usize, a.len());
let (mut b_begin, mut b_end) = (0usize, b.len());

Expand Down
4 changes: 2 additions & 2 deletions vm/src/suggestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn calculate_suggestions<'a>(

for item in dir_iter {
let item_name = item.downcast_ref::<PyStr>()?;
if name.as_str() == item_name.as_str() {
if name.as_bytes() == item_name.as_bytes() {
continue;
}
// No more than 1/3 of the characters should need changed
Expand All @@ -35,7 +35,7 @@ pub fn calculate_suggestions<'a>(
suggestion_distance - 1,
);
let current_distance =
levenshtein_distance(name.as_str(), item_name.as_str(), max_distance);
levenshtein_distance(name.as_bytes(), item_name.as_bytes(), max_distance);
if current_distance > max_distance {
continue;
}
Expand Down