style: The counters code should use atoms rather than strings.

Servo already atomizes the counter names, it makes no sense to copy the string
rather than bumping the refcount.

Differential Revision: https://phabricator.services.mozilla.com/D27061
This commit is contained in:
Emilio Cobos Álvarez 2019-04-15 20:11:45 +00:00
parent a9e473c6e8
commit 498a163cdf
2 changed files with 31 additions and 19 deletions

View file

@ -45,7 +45,7 @@ pub struct CounterPair<Integer> {
ToResolvedValue,
ToShmem,
)]
pub struct CounterIncrement<I>(Counters<I>);
pub struct CounterIncrement<I>(pub Counters<I>);
impl<I> CounterIncrement<I> {
/// Returns a new value for `counter-increment`.
@ -77,7 +77,7 @@ impl<I> Deref for CounterIncrement<I> {
ToResolvedValue,
ToShmem,
)]
pub struct CounterSetOrReset<I>(Counters<I>);
pub struct CounterSetOrReset<I>(pub Counters<I>);
impl<I> CounterSetOrReset<I> {
/// Returns a new value for `counter-set` / `counter-reset`.
@ -102,6 +102,7 @@ impl<I> Deref for CounterSetOrReset<I> {
#[derive(
Clone,
Debug,
Default,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
@ -112,10 +113,13 @@ impl<I> Deref for CounterSetOrReset<I> {
)]
pub struct Counters<I>(#[css(iterable, if_empty = "none")] Box<[CounterPair<I>]>);
impl<I> Default for Counters<I> {
impl<I> Counters<I> {
/// Move out the Box into a vector. This could just return the Box<>, but
/// Vec<> is a bit more convenient because Box<[T]> doesn't implement
/// IntoIter: https://github.com/rust-lang/rust/issues/59878
#[inline]
fn default() -> Self {
Counters(vec![].into_boxed_slice())
pub fn into_vec(self) -> Vec<CounterPair<I>> {
self.0.into_vec()
}
}