From 22eb3018cf61aaed55bbf266ad35934fe78fc60a Mon Sep 17 00:00:00 2001 From: Moreal Date: Sat, 9 Oct 2021 16:00:17 +0900 Subject: [PATCH] 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 --- vm/src/anystr.rs | 4 +++- vm/src/builtins/pystr.rs | 4 ---- vm/src/bytesinner.rs | 4 ---- 3 files changed, 3 insertions(+), 9 deletions(-) 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,