From de8ff5754bf4d6da843d459fee47e03150e78e11 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Fri, 17 Jan 2025 02:11:13 +0000 Subject: [PATCH] refactor(allocator)!: remove `Vec::into_string` --- crates/oxc_allocator/src/vec.rs | 26 +---------------------- crates/oxc_transformer/src/jsx/refresh.rs | 4 ++-- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/crates/oxc_allocator/src/vec.rs b/crates/oxc_allocator/src/vec.rs index 08c4168b1eb3c5..9f476fbc2064a2 100644 --- a/crates/oxc_allocator/src/vec.rs +++ b/crates/oxc_allocator/src/vec.rs @@ -19,9 +19,8 @@ use allocator_api2::vec::Vec as InnerVec; use bumpalo::Bump; #[cfg(any(feature = "serialize", test))] use serde::{ser::SerializeSeq, Serialize, Serializer}; -use simdutf8::basic::Utf8Error; -use crate::{Allocator, Box, String}; +use crate::{Allocator, Box}; /// A `Vec` without [`Drop`], which stores its data in the arena allocator. /// @@ -209,29 +208,6 @@ impl<'alloc, T> Vec<'alloc, T> { } } -impl<'alloc> Vec<'alloc, u8> { - /// Convert `Vec` into [`String`]. - /// - /// # Errors - /// Returns [`Err`] if the `Vec` does not comprise a valid UTF-8 string. - pub fn into_string(self) -> Result, Utf8Error> { - String::from_utf8(self) - } - - /// Convert `Vec` into [`String`], without checking bytes comprise a valid UTF-8 string. - /// - /// Does not copy the contents of the `Vec`, converts in place. This is a zero-cost operation. - /// - /// # SAFETY - /// Caller must ensure this `Vec` comprises a valid UTF-8 string. - #[expect(clippy::missing_safety_doc, clippy::unnecessary_safety_comment)] - #[inline(always)] // `#[inline(always)]` because this is a no-op at runtime - pub unsafe fn into_string_unchecked(self) -> String<'alloc> { - // SAFETY: Caller guarantees vec comprises a valid UTF-8 string. - String::from_utf8_unchecked(self) - } -} - impl<'alloc, T> ops::Deref for Vec<'alloc, T> { type Target = InnerVec; diff --git a/crates/oxc_transformer/src/jsx/refresh.rs b/crates/oxc_transformer/src/jsx/refresh.rs index dcdeb34297b5de..ad1c22aac8bdf4 100644 --- a/crates/oxc_transformer/src/jsx/refresh.rs +++ b/crates/oxc_transformer/src/jsx/refresh.rs @@ -7,7 +7,7 @@ use base64::{ use rustc_hash::FxHashMap; use sha1::{Digest, Sha1}; -use oxc_allocator::{Address, CloneIn, GetAddress, Vec as ArenaVec}; +use oxc_allocator::{Address, CloneIn, GetAddress, String as ArenaString, Vec as ArenaVec}; use oxc_ast::{ast::*, match_expression, AstBuilder, NONE}; use oxc_semantic::{Reference, ReferenceFlags, ScopeFlags, ScopeId, SymbolFlags}; use oxc_span::{Atom, GetSpan, SPAN}; @@ -555,7 +555,7 @@ impl<'a> ReactRefresh<'a, '_> { let mut hashed_key = ArenaVec::from_array_in([0; ENCODED_LEN], ctx.ast.allocator); let encoded_bytes = BASE64_STANDARD.encode_slice(hash, &mut hashed_key).unwrap(); debug_assert_eq!(encoded_bytes, ENCODED_LEN); - let hashed_key = hashed_key.into_string().unwrap(); + let hashed_key = ArenaString::from_utf8(hashed_key).unwrap(); Atom::from(hashed_key) };