mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-19 15:51:33 +00:00
No bug - Revendor rust dependencies
This commit is contained in:
parent
8d75c1de44
commit
6b645f9f38
1
third_party/rust/uluru/.cargo-checksum.json
vendored
Normal file
1
third_party/rust/uluru/.cargo-checksum.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"files":{"Cargo.toml":"72d1bc733f846bd09ec1388588a9f1235aa90984c3bbc36f019e325315787335","README.md":"190ef26732fa5c46032905dc3b4fa6bb27df3e6e7d7f6c924bdd59c389f1edbb","lib.rs":"2581cf44dadb6b1287478b30f5c41bdbe7acd165bd8dbd63b1a48e065c7b0dab"},"package":"cd28fce445fd48f4e2c10ab0d3d8f6a646b11fd2b05228fa94fc83cf69ad6e98"}
|
24
third_party/rust/uluru/Cargo.toml
vendored
Normal file
24
third_party/rust/uluru/Cargo.toml
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g. crates.io) dependencies
|
||||
#
|
||||
# If you believe there's an error in this file please file an
|
||||
# issue against the rust-lang/cargo repository. If you're
|
||||
# editing this file be aware that the upstream Cargo.toml
|
||||
# will likely look very different (and much more reasonable)
|
||||
|
||||
[package]
|
||||
name = "uluru"
|
||||
version = "0.1.0"
|
||||
authors = ["The Servo Project Developers"]
|
||||
description = "A simple, fast, LRU cache implementation"
|
||||
license = "MPL-2.0"
|
||||
|
||||
[lib]
|
||||
name = "uluru"
|
||||
path = "lib.rs"
|
||||
[dependencies.arrayvec]
|
||||
version = "0.3.20"
|
3
third_party/rust/uluru/README.md
vendored
Normal file
3
third_party/rust/uluru/README.md
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# uluru
|
||||
|
||||
A simple, fast, LRU cache implementation used for Servo's style system.
|
238
third_party/rust/uluru/lib.rs
vendored
Normal file
238
third_party/rust/uluru/lib.rs
vendored
Normal file
@ -0,0 +1,238 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
//! A simple LRU cache.
|
||||
|
||||
extern crate arrayvec;
|
||||
|
||||
use arrayvec::{Array, ArrayVec};
|
||||
|
||||
/// A LRU cache using a statically-sized array for storage.
|
||||
///
|
||||
/// The most-recently-used entry is at index `head`. The entries form a linked list, linked to each
|
||||
/// other by indices within the `entries` array. After an entry is added to the array, its index
|
||||
/// never changes, so these links are never invalidated.
|
||||
pub struct LRUCache<T, A: Array<Item=Entry<T>>> {
|
||||
entries: ArrayVec<A>,
|
||||
/// Index of the first entry. If the cache is empty, ignore this field.
|
||||
head: u16,
|
||||
/// Index of the last entry. If the cache is empty, ignore this field.
|
||||
tail: u16,
|
||||
}
|
||||
|
||||
/// An opaque token used as an index into an LRUCache.
|
||||
pub struct CacheIndex(u16);
|
||||
|
||||
/// An entry in an LRUCache.
|
||||
pub struct Entry<T> {
|
||||
val: T,
|
||||
/// Index of the previous entry. If this entry is the head, ignore this field.
|
||||
prev: u16,
|
||||
/// Index of the next entry. If this entry is the tail, ignore this field.
|
||||
next: u16,
|
||||
}
|
||||
|
||||
impl<T, A: Array<Item=Entry<T>>> Default for LRUCache<T, A> {
|
||||
fn default() -> Self {
|
||||
let cache = LRUCache {
|
||||
entries: ArrayVec::new(),
|
||||
head: 0,
|
||||
tail: 0,
|
||||
};
|
||||
assert!(cache.entries.capacity() < u16::max_value() as usize, "Capacity overflow");
|
||||
cache
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, A: Array<Item=Entry<T>>> LRUCache<T, A> {
|
||||
/// Returns the number of elements in the cache.
|
||||
pub fn num_entries(&self) -> usize {
|
||||
self.entries.len()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Touch a given entry, putting it first in the list.
|
||||
pub fn touch(&mut self, idx: CacheIndex) {
|
||||
if idx.0 != self.head {
|
||||
self.remove(idx.0);
|
||||
self.push_front(idx.0);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the front entry in the list (most recently used).
|
||||
pub fn front(&self) -> Option<&T> {
|
||||
self.entries.get(self.head as usize).map(|e| &e.val)
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the front entry in the list (most recently used).
|
||||
pub fn front_mut(&mut self) -> Option<&mut T> {
|
||||
self.entries.get_mut(self.head as usize).map(|e| &mut e.val)
|
||||
}
|
||||
|
||||
/// Iterate over the contents of this cache, from more to less recently
|
||||
/// used.
|
||||
pub fn iter(&self) -> LRUCacheIterator<T, A> {
|
||||
LRUCacheIterator {
|
||||
pos: self.head,
|
||||
done: self.entries.len() == 0,
|
||||
cache: self,
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterate mutably over the contents of this cache.
|
||||
pub fn iter_mut(&mut self) -> LRUCacheMutIterator<T, A> {
|
||||
LRUCacheMutIterator {
|
||||
pos: self.head,
|
||||
done: self.entries.len() == 0,
|
||||
cache: self,
|
||||
}
|
||||
}
|
||||
|
||||
/// Performs a lookup on the cache with the given test routine. Touches
|
||||
/// the result on a hit.
|
||||
pub fn lookup<F, R>(&mut self, mut test_one: F) -> Option<R>
|
||||
where
|
||||
F: FnMut(&mut T) -> Option<R>
|
||||
{
|
||||
let mut result = None;
|
||||
for (i, candidate) in self.iter_mut() {
|
||||
if let Some(r) = test_one(candidate) {
|
||||
result = Some((i, r));
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
match result {
|
||||
None => None,
|
||||
Some((i, r)) => {
|
||||
self.touch(i);
|
||||
let front = self.front_mut().unwrap();
|
||||
debug_assert!(test_one(front).is_some());
|
||||
Some(r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Insert a given key in the cache.
|
||||
pub fn insert(&mut self, val: T) {
|
||||
let entry = Entry { val, prev: 0, next: 0 };
|
||||
|
||||
// If the cache is full, replace the oldest entry. Otherwise, add an entry.
|
||||
let new_head = if self.entries.len() == self.entries.capacity() {
|
||||
let i = self.pop_back();
|
||||
self.entries[i as usize] = entry;
|
||||
i
|
||||
} else {
|
||||
self.entries.push(entry);
|
||||
self.entries.len() as u16 - 1
|
||||
};
|
||||
|
||||
self.push_front(new_head);
|
||||
}
|
||||
|
||||
/// Remove an from the linked list.
|
||||
///
|
||||
/// Note: This only unlinks the entry from the list; it does not remove it from the array.
|
||||
fn remove(&mut self, i: u16) {
|
||||
let prev = self.entries[i as usize].prev;
|
||||
let next = self.entries[i as usize].next;
|
||||
|
||||
if i == self.head {
|
||||
self.head = next;
|
||||
} else {
|
||||
self.entries[prev as usize].next = next;
|
||||
}
|
||||
|
||||
if i == self.tail {
|
||||
self.tail = prev;
|
||||
} else {
|
||||
self.entries[next as usize].prev = prev;
|
||||
}
|
||||
}
|
||||
|
||||
/// Insert a new entry at the head of the list.
|
||||
fn push_front(&mut self, i: u16) {
|
||||
if self.entries.len() == 1 {
|
||||
self.tail = i;
|
||||
} else {
|
||||
self.entries[i as usize].next = self.head;
|
||||
self.entries[self.head as usize].prev = i;
|
||||
}
|
||||
self.head = i;
|
||||
}
|
||||
|
||||
/// Remove the last entry from the linked list. Returns the index of the removed entry.
|
||||
///
|
||||
/// Note: This only unlinks the entry from the list; it does not remove it from the array.
|
||||
fn pop_back(&mut self) -> u16 {
|
||||
let old_tail = self.tail;
|
||||
let new_tail = self.entries[old_tail as usize].prev;
|
||||
self.tail = new_tail;
|
||||
old_tail
|
||||
}
|
||||
|
||||
/// Evict all elements from the cache.
|
||||
pub fn evict_all(&mut self) {
|
||||
self.entries.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// Immutable iterator over values in an LRUCache, from most-recently-used to least-recently-used.
|
||||
pub struct LRUCacheIterator<'a, T: 'a, A: 'a + Array<Item=Entry<T>>> {
|
||||
cache: &'a LRUCache<T, A>,
|
||||
pos: u16,
|
||||
done: bool,
|
||||
}
|
||||
|
||||
impl<'a, T, A> Iterator for LRUCacheIterator<'a, T, A>
|
||||
where T: 'a,
|
||||
A: 'a + Array<Item=Entry<T>>
|
||||
{
|
||||
type Item = (CacheIndex, &'a T);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.done { return None }
|
||||
|
||||
let entry = &self.cache.entries[self.pos as usize];
|
||||
|
||||
let index = CacheIndex(self.pos);
|
||||
if self.pos == self.cache.tail {
|
||||
self.done = true;
|
||||
}
|
||||
self.pos = entry.next;
|
||||
|
||||
Some((index, &entry.val))
|
||||
}
|
||||
}
|
||||
|
||||
/// Mutable iterator over values in an LRUCache, from most-recently-used to least-recently-used.
|
||||
pub struct LRUCacheMutIterator<'a, T: 'a, A: 'a + Array<Item=Entry<T>>> {
|
||||
cache: &'a mut LRUCache<T, A>,
|
||||
pos: u16,
|
||||
done: bool,
|
||||
}
|
||||
|
||||
impl<'a, T, A> Iterator for LRUCacheMutIterator<'a, T, A>
|
||||
where T: 'a,
|
||||
A: 'a + Array<Item=Entry<T>>
|
||||
{
|
||||
type Item = (CacheIndex, &'a mut T);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.done { return None }
|
||||
|
||||
// Use a raw pointer because the compiler doesn't know that subsequent calls can't alias.
|
||||
let entry = unsafe {
|
||||
&mut *(&mut self.cache.entries[self.pos as usize] as *mut Entry<T>)
|
||||
};
|
||||
|
||||
let index = CacheIndex(self.pos);
|
||||
if self.pos == self.cache.tail {
|
||||
self.done = true;
|
||||
}
|
||||
self.pos = entry.next;
|
||||
|
||||
Some((index, &mut entry.val))
|
||||
}
|
||||
}
|
18
toolkit/library/gtest/rust/Cargo.lock
generated
18
toolkit/library/gtest/rust/Cargo.lock
generated
@ -715,13 +715,6 @@ name = "log"
|
||||
version = "0.3.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "lru_cache"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"arrayvec 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "malloc_size_of"
|
||||
version = "0.0.1"
|
||||
@ -1248,7 +1241,6 @@ dependencies = [
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lru_cache 0.0.1",
|
||||
"malloc_size_of 0.0.1",
|
||||
"malloc_size_of_derive 0.0.1",
|
||||
"matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1270,6 +1262,7 @@ dependencies = [
|
||||
"style_traits 0.0.1",
|
||||
"time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uluru 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-bidi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-segmentation 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1399,6 +1392,14 @@ dependencies = [
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uluru"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"arrayvec 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.3"
|
||||
@ -1692,6 +1693,7 @@ dependencies = [
|
||||
"checksum thread_profiler 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf947d192a9be60ef5131cc7a4648886ba89d712f16700ebbf80c8a69d05d48f"
|
||||
"checksum time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "211b63c112206356ef1ff9b19355f43740fc3f85960c598a93d3a3d3ba7beade"
|
||||
"checksum toml 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "736b60249cb25337bc196faa43ee12c705e426f3d55c214d73a4e7be06f92cb4"
|
||||
"checksum uluru 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cd28fce445fd48f4e2c10ab0d3d8f6a646b11fd2b05228fa94fc83cf69ad6e98"
|
||||
"checksum unicode-bidi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a6a2c4e3710edd365cd7e78383153ed739fa31af19f9172f72d3575060f5a43a"
|
||||
"checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f"
|
||||
"checksum unicode-segmentation 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18127285758f0e2c6cf325bb3f3d138a12fee27de4f23e146cd6a179f26c2cf3"
|
||||
|
18
toolkit/library/rust/Cargo.lock
generated
18
toolkit/library/rust/Cargo.lock
generated
@ -714,13 +714,6 @@ name = "log"
|
||||
version = "0.3.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "lru_cache"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"arrayvec 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "malloc_size_of"
|
||||
version = "0.0.1"
|
||||
@ -1240,7 +1233,6 @@ dependencies = [
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lru_cache 0.0.1",
|
||||
"malloc_size_of 0.0.1",
|
||||
"malloc_size_of_derive 0.0.1",
|
||||
"matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1262,6 +1254,7 @@ dependencies = [
|
||||
"style_traits 0.0.1",
|
||||
"time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uluru 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-bidi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-segmentation 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1411,6 +1404,14 @@ dependencies = [
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uluru"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"arrayvec 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.3"
|
||||
@ -1704,6 +1705,7 @@ dependencies = [
|
||||
"checksum thread_profiler 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf947d192a9be60ef5131cc7a4648886ba89d712f16700ebbf80c8a69d05d48f"
|
||||
"checksum time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "211b63c112206356ef1ff9b19355f43740fc3f85960c598a93d3a3d3ba7beade"
|
||||
"checksum toml 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "736b60249cb25337bc196faa43ee12c705e426f3d55c214d73a4e7be06f92cb4"
|
||||
"checksum uluru 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cd28fce445fd48f4e2c10ab0d3d8f6a646b11fd2b05228fa94fc83cf69ad6e98"
|
||||
"checksum unicode-bidi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a6a2c4e3710edd365cd7e78383153ed739fa31af19f9172f72d3575060f5a43a"
|
||||
"checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f"
|
||||
"checksum unicode-segmentation 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18127285758f0e2c6cf325bb3f3d138a12fee27de4f23e146cd6a179f26c2cf3"
|
||||
|
Loading…
x
Reference in New Issue
Block a user