Skip to content

Commit f9bbeac

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Use alloc_typed_unchecked in str.join
Summary: Use new safer APIs. Reviewed By: JakobDegen Differential Revision: D59438549 fbshipit-source-id: b69597ec14f99ac4a1607eeac7ca2f5fd8ea18f9
1 parent 1a406c3 commit f9bbeac

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

starlark/src/stdlib/string.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,8 @@ pub(crate) fn string_methods(builder: &mut MethodsBuilder) {
627627
heap: &'v Heap,
628628
) -> starlark::Result<ValueOfUnchecked<'v, String>> {
629629
#[inline(always)]
630-
fn as_str<'v>(x: Value<'v>) -> anyhow::Result<&'v str> {
631-
<&str>::unpack_named_param(x, "to_join")
630+
fn as_str<'v>(x: Value<'v>) -> anyhow::Result<StringValue<'v>> {
631+
StringValue::unpack_named_param(x, "to_join")
632632
}
633633

634634
let mut it = to_join.get().iterate(heap)?;
@@ -637,13 +637,12 @@ pub(crate) fn string_methods(builder: &mut MethodsBuilder) {
637637
Some(x1) => {
638638
match it.next() {
639639
None => {
640-
as_str(x1)?;
641640
// If there is a singleton we can avoid reallocation
642-
Ok(ValueOfUnchecked::new(x1))
641+
Ok(as_str(x1)?.to_value_of_unchecked().cast())
643642
}
644643
Some(x2) => {
645-
let s1 = as_str(x1)?;
646-
let s2 = as_str(x2)?;
644+
let s1 = as_str(x1)?.as_str();
645+
let s2 = as_str(x2)?.as_str();
647646
// guess towards the upper bound, since we throw away over-allocations quickly
648647
// include a buffer (20 bytes)
649648
let n = it.size_hint().0 + 2;
@@ -655,9 +654,9 @@ pub(crate) fn string_methods(builder: &mut MethodsBuilder) {
655654
r.push_str(s2);
656655
for x in it {
657656
r.push_str(this);
658-
r.push_str(as_str(x)?);
657+
r.push_str(as_str(x)?.as_str());
659658
}
660-
Ok(ValueOfUnchecked::new(heap.alloc(r)))
659+
Ok(heap.alloc_typed_unchecked(r))
661660
}
662661
}
663662
}

0 commit comments

Comments
 (0)