Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ script:
- cargo test
- cargo test --features log-events
- "if [ $TRAVIS_RUST_VERSION = nightly ]; then cargo test --features unstable; fi"
- "if [ $TRAVIS_RUST_VERSION = nightly ]; then cargo test --features heap_size; fi"
- cargo test --features heapsize
- "cd examples/event-log/ && cargo build && cd ../.."
- "cd examples/summarize-events/ && cargo build && cd ../.."
notifications:
Expand Down
13 changes: 3 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "string_cache"
version = "0.2.22"
version = "0.2.23"
authors = [ "The Servo Project Developers" ]
description = "A string interning library for Rust, developed as part of the Servo project."
license = "MIT / Apache-2.0"
Expand All @@ -12,9 +12,6 @@ build = "build.rs"
[lib]
name = "string_cache"

# https://github.com/rust-lang/cargo/issues/1512
doctest = false

[features]

# Enable event logging for generating benchmark traces.
Expand All @@ -25,11 +22,11 @@ log-events = ["rustc-serialize"]
unstable = []

# HeapSizeOf support
heap_size = ["heapsize", "heapsize_plugin"]
heap_size = ["heapsize"]

[dependencies]
lazy_static = "0.2"
serde = ">=0.6, <0.8"
serde = ">=0.6, <0.9"
phf_shared = "0.7.4"
debug_unreachable = "0.1.1"

Expand All @@ -44,10 +41,6 @@ optional = true
version = ">=0.1.1, <0.4"
optional = true

[dependencies.heapsize_plugin]
version = "0.1.4"
optional = true

[build-dependencies]
phf_generator = "0.7.4"
phf_shared = "0.7.4"
21 changes: 15 additions & 6 deletions src/atom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#![allow(non_upper_case_globals)]

#[cfg(feature = "heap_size")]
#[cfg(feature = "heapsize")]
use heapsize::HeapSizeOf;

use serde::{Deserialize, Deserializer, Serialize, Serializer};
Expand Down Expand Up @@ -46,7 +46,7 @@ struct StringCache {
buckets: [Option<Box<StringCacheEntry>>; NB_BUCKETS],
}

#[cfg(feature = "heap_size")]
#[cfg(feature = "heapsize")]
impl HeapSizeOf for StringCache {
fn heap_size_of_children(&self) -> usize {
self.buckets.iter().fold(0, |size, bucket| size + bucket.heap_size_of_children())
Expand All @@ -58,24 +58,31 @@ lazy_static! {
}

/// A token that represents the heap used by the dynamic string cache.
#[cfg(feature = "heap_size")]
#[cfg(feature = "heapsize")]
pub struct StringCacheHeap;

#[cfg(feature = "heap_size")]
#[cfg(feature = "heapsize")]
impl HeapSizeOf for StringCacheHeap {
fn heap_size_of_children(&self) -> usize {
STRING_CACHE.lock().unwrap().heap_size_of_children()
}
}

#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
struct StringCacheEntry {
next_in_bucket: Option<Box<StringCacheEntry>>,
hash: u64,
ref_count: AtomicIsize,
string: Box<str>,
}

#[cfg(feature = "heapsize")]
impl HeapSizeOf for StringCacheEntry {
fn heap_size_of_children(&self) -> usize {
self.next_in_bucket.heap_size_of_children() +
self.string.heap_size_of_children()
}
}

impl StringCacheEntry {
fn new(next: Option<Box<StringCacheEntry>>, hash: u64, string: String)
-> StringCacheEntry {
Expand Down Expand Up @@ -163,7 +170,6 @@ impl StringCache {
// NOTE: Deriving Eq here implies that a given string must always
// be interned the same way.
#[cfg_attr(feature = "unstable", unsafe_no_drop_flag)] // See tests::atom_drop_is_idempotent
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
#[derive(Eq, Hash, PartialEq)]
pub struct Atom {
/// This field is public so that the `atom!()` macro can use it.
Expand All @@ -172,6 +178,9 @@ pub struct Atom {
pub unsafe_data: u64,
}

#[cfg(feature = "heapsize")]
known_heap_size!(0, Atom);

pub struct BorrowedAtom<'a>(pub &'a Atom);

impl<'a> ops::Deref for BorrowedAtom<'a> {
Expand Down
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
#![cfg_attr(test, deny(warnings))]
#![cfg_attr(all(test, feature = "unstable"), feature(test, filling_drop))]
#![cfg_attr(feature = "unstable", feature(unsafe_no_drop_flag))]
#![cfg_attr(feature = "heap_size", feature(plugin, custom_derive))]
#![cfg_attr(feature = "heap_size", plugin(heapsize_plugin))]

#[cfg(all(test, feature = "unstable"))] extern crate test;
#[cfg(feature = "log-events")] extern crate rustc_serialize;
#[cfg(feature = "heap_size")] extern crate heapsize;
#[cfg(feature = "heapsize")] #[macro_use] extern crate heapsize;
#[cfg(test)] extern crate rand;
#[macro_use] extern crate lazy_static;
#[macro_use] extern crate debug_unreachable;
Expand Down
8 changes: 6 additions & 2 deletions src/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ use std::ops;
/// Whether a given string represents a namespace is contextual, so this is
/// a transparent wrapper that will not catch all mistakes.
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Default)]
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub struct Namespace(pub Atom);

#[cfg(feature = "heapsize")]
known_heap_size!(0, Namespace);

pub struct BorrowedNamespace<'a>(pub &'a Namespace);

impl<'a> ops::Deref for BorrowedNamespace<'a> {
Expand All @@ -36,12 +38,14 @@ impl<'a> PartialEq<Namespace> for BorrowedNamespace<'a> {

/// A name with a namespace.
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone)]
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub struct QualName {
pub ns: Namespace,
pub local: Atom,
}

#[cfg(feature = "heapsize")]
known_heap_size!(0, QualName);

impl QualName {
#[inline]
pub fn new(ns: Namespace, local: Atom) -> QualName {
Expand Down