use std::{fs::read_to_string, time::Instant};
use lsp_text_document::{compute_line_offsets, event, position, range, range_at, FullTextDocument};
use lsp_types::{Position, Url};
pub fn new_document(str: &str) -> FullTextDocument {
let url = Url::parse("file://foo");
FullTextDocument::new(url.unwrap(), "text".into(), 0, str.to_string())
}
fn main() {
let s = 10000;
let e = 10100;
let string = read_to_string("test.js").unwrap();
let start = Instant::now();
let mut first_another = "".to_string();
for i in 0..100 {
let text = string.clone();
let start_byte = string
.chars()
.take(s)
.fold(0, |acc, cur| acc + cur.len_utf8());
let end_byte = (&string[s..e])
.chars()
.take(e)
.fold(0, |acc, cur| acc + cur.len_utf8()) + start_byte;
first_another = text[0..start_byte].to_string() + "what" + &text[end_byte..];
}
println!("{:?}", start.elapsed());
let start = Instant::now();
for i in 0..100 {
let text = string.clone();
let _another = text
.chars()
.take(s)
.chain("what".chars())
.chain(text.chars().skip(e))
.collect::<String>();
assert!(&first_another == &_another);
}
println!("{:?}", start.elapsed());
}