Skip to content

Commit fae4cd2

Browse files
committed
refactor(allocator)!: remove Vec::into_string (#8571)
We can use `String::from_utf8` instead (introduced in #8568). This matches `std::str::String`s method.
1 parent e87c001 commit fae4cd2

File tree

2 files changed

+3
-27
lines changed

2 files changed

+3
-27
lines changed

crates/oxc_allocator/src/vec.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ use allocator_api2::vec::Vec as InnerVec;
1919
use bumpalo::Bump;
2020
#[cfg(any(feature = "serialize", test))]
2121
use serde::{ser::SerializeSeq, Serialize, Serializer};
22-
use simdutf8::basic::Utf8Error;
2322

24-
use crate::{Allocator, Box, String};
23+
use crate::{Allocator, Box};
2524

2625
/// A `Vec` without [`Drop`], which stores its data in the arena allocator.
2726
///
@@ -209,29 +208,6 @@ impl<'alloc, T> Vec<'alloc, T> {
209208
}
210209
}
211210

212-
impl<'alloc> Vec<'alloc, u8> {
213-
/// Convert `Vec<u8>` into [`String`].
214-
///
215-
/// # Errors
216-
/// Returns [`Err`] if the `Vec` does not comprise a valid UTF-8 string.
217-
pub fn into_string(self) -> Result<String<'alloc>, Utf8Error> {
218-
String::from_utf8(self)
219-
}
220-
221-
/// Convert `Vec<u8>` into [`String`], without checking bytes comprise a valid UTF-8 string.
222-
///
223-
/// Does not copy the contents of the `Vec`, converts in place. This is a zero-cost operation.
224-
///
225-
/// # SAFETY
226-
/// Caller must ensure this `Vec<u8>` comprises a valid UTF-8 string.
227-
#[expect(clippy::missing_safety_doc, clippy::unnecessary_safety_comment)]
228-
#[inline(always)] // `#[inline(always)]` because this is a no-op at runtime
229-
pub unsafe fn into_string_unchecked(self) -> String<'alloc> {
230-
// SAFETY: Caller guarantees vec comprises a valid UTF-8 string.
231-
String::from_utf8_unchecked(self)
232-
}
233-
}
234-
235211
impl<'alloc, T> ops::Deref for Vec<'alloc, T> {
236212
type Target = InnerVec<T, &'alloc Bump>;
237213

crates/oxc_transformer/src/jsx/refresh.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use base64::{
77
use rustc_hash::FxHashMap;
88
use sha1::{Digest, Sha1};
99

10-
use oxc_allocator::{Address, CloneIn, GetAddress, Vec as ArenaVec};
10+
use oxc_allocator::{Address, CloneIn, GetAddress, String as ArenaString, Vec as ArenaVec};
1111
use oxc_ast::{ast::*, match_expression, AstBuilder, NONE};
1212
use oxc_semantic::{Reference, ReferenceFlags, ScopeFlags, ScopeId, SymbolFlags};
1313
use oxc_span::{Atom, GetSpan, SPAN};
@@ -555,7 +555,7 @@ impl<'a> ReactRefresh<'a, '_> {
555555
let mut hashed_key = ArenaVec::from_array_in([0; ENCODED_LEN], ctx.ast.allocator);
556556
let encoded_bytes = BASE64_STANDARD.encode_slice(hash, &mut hashed_key).unwrap();
557557
debug_assert_eq!(encoded_bytes, ENCODED_LEN);
558-
let hashed_key = hashed_key.into_string().unwrap();
558+
let hashed_key = ArenaString::from_utf8(hashed_key).unwrap();
559559
Atom::from(hashed_key)
560560
};
561561

0 commit comments

Comments
 (0)