Skip to content

Commit 22eb301

Browse files
committed
Deprecate AnyStr::chars_len again
I implemented 84e5f42 again but I deprecate the method again because it is too expensive. See also RustPython#3164 (comment)
1 parent 868f104 commit 22eb301

3 files changed

Lines changed: 3 additions & 9 deletions

File tree

vm/src/anystr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ pub trait AnyStr<'s>: 's {
145145
// FIXME: get_chars is expensive for str
146146
fn get_chars(&self, range: std::ops::Range<usize>) -> &Self;
147147
fn bytes_len(&self) -> usize;
148-
fn chars_len(&self) -> usize; // cannot access to cache here
148+
// NOTE: str::chars().count() consumes the O(n) time. But pystr::char_len does cache.
149+
// So using chars_len directly is too expensive and the below method shouldn't be implemented.
150+
// fn chars_len(&self) -> usize;
149151
fn is_empty(&self) -> bool;
150152

151153
fn py_add(&self, other: &Self) -> Self::Container {

vm/src/builtins/pystr.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,10 +1645,6 @@ impl<'s> AnyStr<'s> for str {
16451645
Self::len(self)
16461646
}
16471647

1648-
fn chars_len(&self) -> usize {
1649-
self.chars().count()
1650-
}
1651-
16521648
fn py_split_whitespace<F>(&self, maxsplit: isize, convert: F) -> Vec<PyObjectRef>
16531649
where
16541650
F: Fn(&Self) -> PyObjectRef,

vm/src/bytesinner.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,10 +1073,6 @@ impl<'s> AnyStr<'s> for [u8] {
10731073
Self::len(self)
10741074
}
10751075

1076-
fn chars_len(&self) -> usize {
1077-
Self::len(self)
1078-
}
1079-
10801076
fn py_split_whitespace<F>(&self, maxsplit: isize, convert: F) -> Vec<PyObjectRef>
10811077
where
10821078
F: Fn(&Self) -> PyObjectRef,

0 commit comments

Comments
 (0)