Change language::min() to a constant

Co-authored-by: Antonio Scandurra <me@as-cii.com>
Co-authored-by: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Keith Simmons 2022-03-24 10:35:30 -07:00
parent f6805eb802
commit ab631cf6c3
10 changed files with 33 additions and 62 deletions

View file

@ -12,21 +12,17 @@ pub struct Anchor {
}
impl Anchor {
pub fn build_min() -> Self {
Self {
timestamp: clock::Local::MIN,
offset: usize::MIN,
bias: Bias::Left,
}
}
pub const MIN: Self = Self {
timestamp: clock::Local::MIN,
offset: usize::MIN,
bias: Bias::Left,
};
pub fn build_max() -> Self {
Self {
timestamp: clock::Local::MAX,
offset: usize::MAX,
bias: Bias::Right,
}
}
pub const MAX: Self = Self {
timestamp: clock::Local::MAX,
offset: usize::MAX,
bias: Bias::Right,
};
pub fn cmp(&self, other: &Anchor, buffer: &BufferSnapshot) -> Result<Ordering> {
let fragment_id_comparison = if self.timestamp == other.timestamp {

View file

@ -1318,8 +1318,8 @@ impl Buffer {
let mut futures = Vec::new();
for anchor in anchors {
if !self.version.observed(anchor.timestamp)
&& *anchor != Anchor::build_max()
&& *anchor != Anchor::build_min()
&& *anchor != Anchor::MAX
&& *anchor != Anchor::MIN
{
let (tx, rx) = oneshot::channel();
self.edit_id_resolvers
@ -1638,9 +1638,9 @@ impl BufferSnapshot {
let mut position = D::default();
anchors.map(move |anchor| {
if *anchor == Anchor::build_min() {
if *anchor == Anchor::MIN {
return D::default();
} else if *anchor == Anchor::build_max() {
} else if *anchor == Anchor::MAX {
return D::from_text_summary(&self.visible_text.summary());
}
@ -1680,9 +1680,9 @@ impl BufferSnapshot {
where
D: TextDimension,
{
if *anchor == Anchor::build_min() {
if *anchor == Anchor::MIN {
D::default()
} else if *anchor == Anchor::build_max() {
} else if *anchor == Anchor::MAX {
D::from_text_summary(&self.visible_text.summary())
} else {
let anchor_key = InsertionFragmentKey {
@ -1718,9 +1718,9 @@ impl BufferSnapshot {
}
fn fragment_id_for_anchor(&self, anchor: &Anchor) -> &Locator {
if *anchor == Anchor::build_min() {
if *anchor == Anchor::MIN {
&locator::MIN
} else if *anchor == Anchor::build_max() {
} else if *anchor == Anchor::MAX {
&locator::MAX
} else {
let anchor_key = InsertionFragmentKey {
@ -1758,9 +1758,9 @@ impl BufferSnapshot {
pub fn anchor_at<T: ToOffset>(&self, position: T, bias: Bias) -> Anchor {
let offset = position.to_offset(self);
if bias == Bias::Left && offset == 0 {
Anchor::build_min()
Anchor::MIN
} else if bias == Bias::Right && offset == self.len() {
Anchor::build_max()
Anchor::MAX
} else {
let mut fragment_cursor = self.fragments.cursor::<usize>();
fragment_cursor.seek(&offset, bias, &None);
@ -1775,9 +1775,7 @@ impl BufferSnapshot {
}
pub fn can_resolve(&self, anchor: &Anchor) -> bool {
*anchor == Anchor::build_min()
|| *anchor == Anchor::build_max()
|| self.version.observed(anchor.timestamp)
*anchor == Anchor::MIN || *anchor == Anchor::MAX || self.version.observed(anchor.timestamp)
}
pub fn clip_offset(&self, offset: usize, bias: Bias) -> usize {
@ -1799,7 +1797,7 @@ impl BufferSnapshot {
where
D: TextDimension + Ord,
{
self.edits_since_in_range(since, Anchor::build_min()..Anchor::build_max())
self.edits_since_in_range(since, Anchor::MIN..Anchor::MAX)
}
pub fn edited_ranges_for_transaction<'a, D>(