Skip to content

Commit 939e77b

Browse files
committed
PrefixMatcher wasn't totally ordered + cleanup.
1 parent 6bfddb1 commit 939e77b

File tree

5 files changed

+23
-44
lines changed

5 files changed

+23
-44
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
![](https://img.shields.io/github/license/WINSDK/bite)
1616

1717
`BiTE` is a platform-agnostic executable analysis tool. It aims to offer an
18-
environment for inspecting the content of binaries and it's debug info. While it is
19-
still in early development, it supports various architectures.
18+
environment for inspecting the content of binaries and their debug info. While it is
19+
still in early development, various architectures are supported.
2020

2121
## Showcase
2222

debugvault/src/dwarf.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,13 @@ impl Dwarf {
6363
Ok(Dwarf { file_attrs })
6464
}
6565

66-
#[allow(dead_code)]
6766
pub fn load(path: &Path) -> Result<Self> {
6867
let file = std::fs::File::open(path)?;
6968
let mmap = unsafe { memmap2::Mmap::map(&file)? };
7069
let obj = object::File::parse(&*mmap)?;
7170
Self::parse(&obj)
7271
}
7372

74-
#[allow(dead_code)]
7573
pub fn merge(&mut self, other: Self) {
7674
self.file_attrs.extend(other.file_attrs);
7775
}

debugvault/src/itanium/error.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ impl fmt::Display for Error {
8282
}
8383
}
8484

85-
#[cfg(feature = "std")]
86-
impl error::Error for Error {
85+
impl std::error::Error for Error {
8786
fn description(&self) -> &str {
8887
match *self {
8988
Error::UnexpectedEnd => "mangled symbol ends abruptly",
@@ -98,10 +97,6 @@ impl error::Error for Error {
9897
Error::ForwardTemplateArgReference => {
9998
"reference to a template arg from itself or a later template arg"
10099
}
101-
Error::BadFunctionArgReference => {
102-
"reference to a function arg that is either out-of-bounds, or in a context \
103-
without function args"
104-
}
105100
Error::BadLeafNameReference => {
106101
"reference to a leaf name in a context where there is no current leaf name"
107102
}

debugvault/src/prefix.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,21 @@ use std::{cmp::Ordering, sync::Arc};
33

44
use crate::Symbol;
55

6-
fn cmp(a: &str, b: &str) -> Ordering {
6+
#[inline]
7+
fn sort_cmp(a: &str, b: &str) -> Ordering {
8+
for (x, y) in a.chars().zip(b.chars()) {
9+
if x < y {
10+
return Ordering::Less;
11+
} else if x > y {
12+
return Ordering::Greater;
13+
}
14+
}
15+
16+
a.len().cmp(&b.len())
17+
}
18+
19+
#[inline]
20+
fn find_cmp(a: &str, b: &str) -> Ordering {
721
for (x, y) in a.chars().zip(b.chars()) {
822
if x < y {
923
return Ordering::Less;
@@ -29,28 +43,27 @@ impl PrefixMatcher {
2943

3044
/// Sorts elements to allow for searching.
3145
pub fn reorder(&mut self) {
32-
self.items.sort_unstable_by(|a, b| cmp(a.as_str(), b.as_str()));
46+
self.items.sort_unstable_by(|a, b| sort_cmp(a.as_str(), b.as_str()));
3347
self.items.shrink_to_fit();
3448
}
3549

3650
/// Find some given prefix and return a range back into the items.
3751
/// Must call [`PrefixMatch::reorder`] before calling this.
3852
pub fn find(&self, prefix: &str) -> Match {
3953
// This works as cmp() will return Ordering::Equal if the prefix matches.
40-
let mid = match self.items.binary_search_by(|item| cmp(item.as_str(), prefix)) {
41-
Ok(idx) => idx,
42-
Err(_) => return Match { range: 0..0 },
54+
let Ok(mid) = self.items.binary_search_by(|item| find_cmp(item.as_str(), prefix)) else {
55+
return Match { range: 0..0 };
4356
};
4457

4558
// Look left and try to find more matching prefixes
4659
let mut start = mid;
47-
while start != 0 && self.items[start - 1].as_str().starts_with(prefix) {
60+
while start > 0 && self.items[start - 1].as_str().starts_with(prefix) {
4861
start -= 1;
4962
}
5063

5164
// Look right and try to find more matching prefixes
5265
let mut end = mid;
53-
while end != self.items.len() && self.items[end + 1].as_str().starts_with(prefix) {
66+
while end + 1 < self.items.len() && self.items[end + 1].as_str().starts_with(prefix) {
5467
end += 1;
5568
}
5669

gui/src/widgets/text_edit.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ pub struct TextEditOutput {
3535
///
3636
/// Attention: You also need to `store` the updated state.
3737
#[derive(Clone, Default)]
38-
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
39-
#[cfg_attr(feature = "serde", serde(default))]
4038
pub struct TextEditState {
4139
cursor_range: Option<CursorRange>,
4240

@@ -45,15 +43,12 @@ pub struct TextEditState {
4543
ccursor_range: Option<CCursorRange>,
4644

4745
/// Wrapped in Arc for cheaper clones.
48-
#[cfg_attr(feature = "serde", serde(skip))]
4946
pub(crate) undoer: Arc<Mutex<Undoer>>,
5047

5148
// If IME candidate window is shown on this text edit.
52-
#[cfg_attr(feature = "serde", serde(skip))]
5349
pub(crate) has_ime: bool,
5450

5551
// Visual offset when editing singleline text bigger than the width.
56-
#[cfg_attr(feature = "serde", serde(skip))]
5752
pub(crate) singleline_offset: f32,
5853
}
5954

@@ -1020,28 +1015,6 @@ fn events(
10201015
None
10211016
}
10221017
}
1023-
1024-
#[cfg(feature = "accesskit")]
1025-
Event::AccessKitActionRequest(accesskit::ActionRequest {
1026-
action: accesskit::Action::SetTextSelection,
1027-
target,
1028-
data: Some(accesskit::ActionData::SetTextSelection(selection)),
1029-
}) => {
1030-
if id.accesskit_id() == *target {
1031-
let primary =
1032-
ccursor_from_accesskit_text_position(id, galley, &selection.focus);
1033-
let secondary =
1034-
ccursor_from_accesskit_text_position(id, galley, &selection.anchor);
1035-
if let (Some(primary), Some(secondary)) = (primary, secondary) {
1036-
Some(CCursorRange { primary, secondary })
1037-
} else {
1038-
None
1039-
}
1040-
} else {
1041-
None
1042-
}
1043-
}
1044-
10451018
_ => None,
10461019
};
10471020

0 commit comments

Comments
 (0)