Skip to content

Commit

Permalink
perf: toString
Browse files Browse the repository at this point in the history
  • Loading branch information
h-a-n-a committed Dec 10, 2024
1 parent 64844d1 commit ea587c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{
borrow::{BorrowMut, Cow},
cell::{OnceCell, RefCell},
fmt::Display,
marker::PhantomData,
ops::Range,
};
Expand Down Expand Up @@ -1287,7 +1286,7 @@ pub fn stream_and_get_source_and_map<'a, S: StreamChunks>(
(generated_info, map)
}

pub trait SourceText<'a>: Default + Clone + Display {
pub trait SourceText<'a>: Default + Clone + ToString {
fn split_into_lines(&self) -> impl Iterator<Item = Self>;
fn len(&self) -> usize;
fn ends_with(&self, value: &str) -> bool;
Expand Down
12 changes: 6 additions & 6 deletions src/rope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::{
borrow::Cow,
cell::RefCell,
collections::VecDeque,
fmt::Display,
hash::Hash,
ops::{Bound, RangeBounds},
rc::Rc,
Expand Down Expand Up @@ -415,15 +414,16 @@ impl Default for Rope<'_> {
}
}

impl Display for Rope<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl ToString for Rope<'_> {
fn to_string(&self) -> String {
match &self.0 {
Repr::Simple(s) => write!(f, "{}", s),
Repr::Simple(s) => s.to_string(),
Repr::Complex(data) => {
let mut s = String::with_capacity(self.len());
for (chunk, _) in data.iter() {
write!(f, "{}", chunk)?;
s.push_str(chunk);
}
Ok(())
s
}
}
}
Expand Down

0 comments on commit ea587c2

Please sign in to comment.