Skip to content

Commit e7cfb8e

Browse files
author
bors-servo
authored
Auto merge of #166 - nox:serde, r=SimonSapin
Allow serde 0.8 and remove use of compiler plugins <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/string-cache/166) <!-- Reviewable:end -->
2 parents 12008ae + 07abb7b commit e7cfb8e

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ script:
1212
- cargo test
1313
- cargo test --features log-events
1414
- "if [ $TRAVIS_RUST_VERSION = nightly ]; then cargo test --features unstable; fi"
15-
- "if [ $TRAVIS_RUST_VERSION = nightly ]; then cargo test --features heap_size; fi"
15+
- cargo test --features heapsize
1616
- "cd examples/event-log/ && cargo build && cd ../.."
1717
- "cd examples/summarize-events/ && cargo build && cd ../.."
1818
notifications:

Cargo.toml

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

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

15-
# https://github.com/rust-lang/cargo/issues/1512
16-
doctest = false
17-
1815
[features]
1916

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

2724
# HeapSizeOf support
28-
heap_size = ["heapsize", "heapsize_plugin"]
25+
heap_size = ["heapsize"]
2926

3027
[dependencies]
3128
lazy_static = "0.2"
32-
serde = ">=0.6, <0.8"
29+
serde = ">=0.6, <0.9"
3330
phf_shared = "0.7.4"
3431
debug_unreachable = "0.1.1"
3532

@@ -44,10 +41,6 @@ optional = true
4441
version = ">=0.1.1, <0.4"
4542
optional = true
4643

47-
[dependencies.heapsize_plugin]
48-
version = "0.1.4"
49-
optional = true
50-
5144
[build-dependencies]
5245
phf_generator = "0.7.4"
5346
phf_shared = "0.7.4"

src/atom/mod.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#![allow(non_upper_case_globals)]
1111

12-
#[cfg(feature = "heap_size")]
12+
#[cfg(feature = "heapsize")]
1313
use heapsize::HeapSizeOf;
1414

1515
use serde::{Deserialize, Deserializer, Serialize, Serializer};
@@ -46,7 +46,7 @@ struct StringCache {
4646
buckets: [Option<Box<StringCacheEntry>>; NB_BUCKETS],
4747
}
4848

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

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

64-
#[cfg(feature = "heap_size")]
64+
#[cfg(feature = "heapsize")]
6565
impl HeapSizeOf for StringCacheHeap {
6666
fn heap_size_of_children(&self) -> usize {
6767
STRING_CACHE.lock().unwrap().heap_size_of_children()
6868
}
6969
}
7070

71-
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
7271
struct StringCacheEntry {
7372
next_in_bucket: Option<Box<StringCacheEntry>>,
7473
hash: u64,
7574
ref_count: AtomicIsize,
7675
string: Box<str>,
7776
}
7877

78+
#[cfg(feature = "heapsize")]
79+
impl HeapSizeOf for StringCacheEntry {
80+
fn heap_size_of_children(&self) -> usize {
81+
self.next_in_bucket.heap_size_of_children() +
82+
self.string.heap_size_of_children()
83+
}
84+
}
85+
7986
impl StringCacheEntry {
8087
fn new(next: Option<Box<StringCacheEntry>>, hash: u64, string: String)
8188
-> StringCacheEntry {
@@ -163,7 +170,6 @@ impl StringCache {
163170
// NOTE: Deriving Eq here implies that a given string must always
164171
// be interned the same way.
165172
#[cfg_attr(feature = "unstable", unsafe_no_drop_flag)] // See tests::atom_drop_is_idempotent
166-
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
167173
#[derive(Eq, Hash, PartialEq)]
168174
pub struct Atom {
169175
/// This field is public so that the `atom!()` macro can use it.
@@ -172,6 +178,9 @@ pub struct Atom {
172178
pub unsafe_data: u64,
173179
}
174180

181+
#[cfg(feature = "heapsize")]
182+
known_heap_size!(0, Atom);
183+
175184
pub struct BorrowedAtom<'a>(pub &'a Atom);
176185

177186
impl<'a> ops::Deref for BorrowedAtom<'a> {

src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
#![cfg_attr(test, deny(warnings))]
1414
#![cfg_attr(all(test, feature = "unstable"), feature(test, filling_drop))]
1515
#![cfg_attr(feature = "unstable", feature(unsafe_no_drop_flag))]
16-
#![cfg_attr(feature = "heap_size", feature(plugin, custom_derive))]
17-
#![cfg_attr(feature = "heap_size", plugin(heapsize_plugin))]
1816

1917
#[cfg(all(test, feature = "unstable"))] extern crate test;
2018
#[cfg(feature = "log-events")] extern crate rustc_serialize;
21-
#[cfg(feature = "heap_size")] extern crate heapsize;
19+
#[cfg(feature = "heapsize")] #[macro_use] extern crate heapsize;
2220
#[cfg(test)] extern crate rand;
2321
#[macro_use] extern crate lazy_static;
2422
#[macro_use] extern crate debug_unreachable;

src/namespace.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ use std::ops;
1616
/// Whether a given string represents a namespace is contextual, so this is
1717
/// a transparent wrapper that will not catch all mistakes.
1818
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Default)]
19-
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
2019
pub struct Namespace(pub Atom);
2120

21+
#[cfg(feature = "heapsize")]
22+
known_heap_size!(0, Namespace);
23+
2224
pub struct BorrowedNamespace<'a>(pub &'a Namespace);
2325

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

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

46+
#[cfg(feature = "heapsize")]
47+
known_heap_size!(0, QualName);
48+
4549
impl QualName {
4650
#[inline]
4751
pub fn new(ns: Namespace, local: Atom) -> QualName {

0 commit comments

Comments
 (0)