From e99beff76162afdafc3fd8c34b12913939f9acce Mon Sep 17 00:00:00 2001 From: Thomas Orozco Date: Wed, 4 Jan 2023 01:02:51 -0800 Subject: [PATCH] buck2: switch to compact_str instead of smartstring Summary: Upsides: - It seems more actively maintained. - Note: on Github issues, they have a couple open reports of fuzz failures (from their automation) but those are from a branch, not master. - It doesn't have this frustrating bug: https://github.com/bodil/smartstring/issues/7 Downsides: - It doesn't convert String to an inlined value in `From`, but we don't actually rely on this (we use small strings mostly when working with directories where those elements are produced via an iterator of FileName). Reviewed By: ndmitchell Differential Revision: D42313656 fbshipit-source-id: 0708866fced3b32941047755b770244287f6ad94 --- allocative/Cargo.toml | 2 +- allocative/src/impls/{smartstring.rs => compact_str.rs} | 9 ++++----- allocative/src/impls/mod.rs | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) rename allocative/src/impls/{smartstring.rs => compact_str.rs} (83%) diff --git a/allocative/Cargo.toml b/allocative/Cargo.toml index ce9f576..f0225ef 100644 --- a/allocative/Cargo.toml +++ b/allocative/Cargo.toml @@ -22,7 +22,7 @@ hashbrown = { version = "0.12.3", optional = true } indexmap = { version = "1.9.1", optional = true } num-bigint = { version = "0.4.3", optional = true } parking_lot = { version = "0.11.2", optional = true } -smartstring = { version = "0.2.10", optional = true } +compact_str = { version = "0.6.1", optional = true } once_cell = { version = "1.16.0", optional = true } owning_ref = { version = "0.4.1", optional = true } prost-types = { version = "0.11.2", optional = true } diff --git a/allocative/src/impls/smartstring.rs b/allocative/src/impls/compact_str.rs similarity index 83% rename from allocative/src/impls/smartstring.rs rename to allocative/src/impls/compact_str.rs index 1b65768..f848df4 100644 --- a/allocative/src/impls/smartstring.rs +++ b/allocative/src/impls/compact_str.rs @@ -7,10 +7,9 @@ * of this source tree. */ -#![cfg(feature = "smartstring")] +#![cfg(feature = "compact_str")] -use smartstring::SmartString; -use smartstring::SmartStringMode; +use compact_str::CompactString; use crate::allocative_trait::Allocative; use crate::impls::common::PTR_NAME; @@ -18,10 +17,10 @@ use crate::impls::common::UNUSED_CAPACITY_NAME; use crate::key::Key; use crate::visitor::Visitor; -impl Allocative for SmartString { +impl Allocative for CompactString { fn visit<'a, 'b: 'a>(&self, visitor: &'a mut Visitor<'b>) { let mut visitor = visitor.enter_self_sized::(); - if !self.is_inline() { + if self.is_heap_allocated() { let mut visitor = visitor.enter_unique(PTR_NAME, std::mem::size_of::<*const u8>()); visitor.visit_simple(Key::new("str"), self.len()); let unused_capacity = self.capacity() - self.len(); diff --git a/allocative/src/impls/mod.rs b/allocative/src/impls/mod.rs index 122ae96..3e1b391 100644 --- a/allocative/src/impls/mod.rs +++ b/allocative/src/impls/mod.rs @@ -12,6 +12,7 @@ mod anyhow; mod bumpalo; pub(crate) mod common; +mod compact_str; mod dashmap; mod either; mod futures; @@ -27,6 +28,5 @@ mod prost_types; mod relative_path; mod sequence_trie; mod smallvec; -mod smartstring; mod sorted_vector_map; mod std;