Skip to content

Commit

Permalink
buck2: switch to compact_str instead of smartstring
Browse files Browse the repository at this point in the history
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: bodil/smartstring#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
  • Loading branch information
krallin authored and facebook-github-bot committed Jan 4, 2023
1 parent 4fb57a9 commit e99beff
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion allocative/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@
* 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;
use crate::impls::common::UNUSED_CAPACITY_NAME;
use crate::key::Key;
use crate::visitor::Visitor;

impl<M: SmartStringMode + 'static> Allocative for SmartString<M> {
impl Allocative for CompactString {
fn visit<'a, 'b: 'a>(&self, visitor: &'a mut Visitor<'b>) {
let mut visitor = visitor.enter_self_sized::<Self>();
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();
Expand Down
2 changes: 1 addition & 1 deletion allocative/src/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
mod anyhow;
mod bumpalo;
pub(crate) mod common;
mod compact_str;
mod dashmap;
mod either;
mod futures;
Expand All @@ -27,6 +28,5 @@ mod prost_types;
mod relative_path;
mod sequence_trie;
mod smallvec;
mod smartstring;
mod sorted_vector_map;
mod std;

0 comments on commit e99beff

Please sign in to comment.