Deprecate AnyStr::chars_len again

I implemented 84e5f4212d6a5707748293b9603493661ac33355 again but I deprecate
the method again because it is too expensive.
See also https://github.com/RustPython/RustPython/pull/3164#discussion_r725438699
This commit is contained in:
Moreal
2021-10-09 16:00:17 +09:00
parent 868f104a98
commit 22eb3018cf
3 changed files with 3 additions and 9 deletions

View File

@@ -145,7 +145,9 @@ pub trait AnyStr<'s>: 's {
// FIXME: get_chars is expensive for str
fn get_chars(&self, range: std::ops::Range<usize>) -> &Self;
fn bytes_len(&self) -> usize;
fn chars_len(&self) -> usize; // cannot access to cache here
// NOTE: str::chars().count() consumes the O(n) time. But pystr::char_len does cache.
// So using chars_len directly is too expensive and the below method shouldn't be implemented.
// fn chars_len(&self) -> usize;
fn is_empty(&self) -> bool;
fn py_add(&self, other: &Self) -> Self::Container {

View File

@@ -1645,10 +1645,6 @@ impl<'s> AnyStr<'s> for str {
Self::len(self)
}
fn chars_len(&self) -> usize {
self.chars().count()
}
fn py_split_whitespace<F>(&self, maxsplit: isize, convert: F) -> Vec<PyObjectRef>
where
F: Fn(&Self) -> PyObjectRef,

View File

@@ -1073,10 +1073,6 @@ impl<'s> AnyStr<'s> for [u8] {
Self::len(self)
}
fn chars_len(&self) -> usize {
Self::len(self)
}
fn py_split_whitespace<F>(&self, maxsplit: isize, convert: F) -> Vec<PyObjectRef>
where
F: Fn(&Self) -> PyObjectRef,