Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion .cargo/release-nightly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ rustflags = [
[unstable]
panic-immediate-abort = true
build-std = ["std", "panic_abort"]
build-std-features = ["default", "optimize_for_size"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

9 changes: 1 addition & 8 deletions crates/edit/src/bin/edit/draw_filepicker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,7 @@ fn draw_dialog_saveas_refresh_files(state: &mut State) {
entries.sort_unstable_by(|a, b| {
let a = a.as_bytes();
let b = b.as_bytes();

let a_is_dir = a.last() == Some(&b'/');
let b_is_dir = b.last() == Some(&b'/');

match b_is_dir.cmp(&a_is_dir) {
Ordering::Equal => icu::compare_strings(a, b),
other => other,
}
icu::compare_strings(a, b)
});
}

Expand Down
32 changes: 31 additions & 1 deletion crates/edit/src/icu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,27 @@ pub fn compare_strings(a: &[u8], b: &[u8]) -> Ordering {
if let Ok(f) = init_if_needed() {
let mut status = icu_ffi::U_ZERO_ERROR;
coll = (f.ucol_open)(c"".as_ptr(), &mut status);
// Turns on Unicode normalization. I'm not 100% sure if it's needed, but it only has a
// small-ish performance impact and sounds like it's required for correct filename sorting.
(f.ucol_setAttribute)(
coll,
icu_ffi::UCOL_NORMALIZATION_MODE,
icu_ffi::UCOL_ON,
&mut status,
);
// Ensure that "file2" < "file10", even though '2' > '1'.
// NOTE: This has a _huge_ performance impact. It's roughly 5x slower for our purpose of
// sorting filenames. If it becomes an issue, we could use `ucol_getSortKey` (only +25%).
// (`ucol_strcollUTF8` is faster if `UCOL_NUMERIC_COLLATION` isn't used.)
(f.ucol_setAttribute)(
coll,
icu_ffi::UCOL_NUMERIC_COLLATION,
icu_ffi::UCOL_ON,
&mut status,
);
if status.is_failure() {
coll = null_mut();
}
}

ROOT_COLLATOR = Some(coll);
Expand Down Expand Up @@ -920,6 +941,7 @@ struct LibraryFunctions {

// LIBICUI18N_PROC_NAMES
ucol_open: icu_ffi::ucol_open,
ucol_setAttribute: icu_ffi::ucol_setAttribute,
ucol_strcollUTF8: icu_ffi::ucol_strcollUTF8,
uregex_open: icu_ffi::uregex_open,
uregex_close: icu_ffi::uregex_close,
Expand Down Expand Up @@ -954,8 +976,9 @@ const LIBICUUC_PROC_NAMES: [*const c_char; 10] = [
];

// Found in libicui18n.so on UNIX, icuin.dll/icu.dll on Windows.
const LIBICUI18N_PROC_NAMES: [*const c_char; 11] = [
const LIBICUI18N_PROC_NAMES: [*const c_char; 12] = [
proc_name!("ucol_open"),
proc_name!("ucol_setAttribute"),
proc_name!("ucol_strcollUTF8"),
proc_name!("uregex_open"),
proc_name!("uregex_close"),
Expand Down Expand Up @@ -1162,6 +1185,13 @@ mod icu_ffi {
pub type ucol_open =
unsafe extern "C" fn(loc: *const c_char, status: &mut UErrorCode) -> *mut UCollator;

pub type ucol_setAttribute =
unsafe extern "C" fn(coll: *mut UCollator, attr: i32, value: i32, status: &mut UErrorCode);

pub const UCOL_NORMALIZATION_MODE: i32 = 4;
pub const UCOL_NUMERIC_COLLATION: i32 = 7;
pub const UCOL_ON: i32 = 17;

pub type ucol_strcollUTF8 = unsafe extern "C" fn(
coll: *mut UCollator,
source: *const u8,
Expand Down