diff --git a/vm/src/anystr.rs b/vm/src/anystr.rs index 7cd88926e..ba7cd17d2 100644 --- a/vm/src/anystr.rs +++ b/vm/src/anystr.rs @@ -145,7 +145,9 @@ pub trait AnyStr<'s>: 's { // FIXME: get_chars is expensive for str fn get_chars(&self, range: std::ops::Range) -> &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 { diff --git a/vm/src/builtins/pystr.rs b/vm/src/builtins/pystr.rs index 64c46d20e..ec3ea2ae7 100644 --- a/vm/src/builtins/pystr.rs +++ b/vm/src/builtins/pystr.rs @@ -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(&self, maxsplit: isize, convert: F) -> Vec where F: Fn(&Self) -> PyObjectRef, diff --git a/vm/src/bytesinner.rs b/vm/src/bytesinner.rs index 8becd5592..61c391710 100644 --- a/vm/src/bytesinner.rs +++ b/vm/src/bytesinner.rs @@ -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(&self, maxsplit: isize, convert: F) -> Vec where F: Fn(&Self) -> PyObjectRef,