Skip to content

Commit d6582d4

Browse files
committed
Upgrade Rust.
1 parent be58e45 commit d6582d4

4 files changed

Lines changed: 17 additions & 16 deletions

File tree

Makefile.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ RUST_SRC=$(shell find $(VPATH)/. -type f -name '*.rs')
99
.PHONY: all
1010
all: libstring-cache.dummy
1111

12-
.PHONY: libstring-cache.dummy
1312
libstring-cache.dummy: lib.rs $(RUST_SRC) $(EXT_DEPS)
1413
$(RUSTC) $(RUSTFLAGS) $< --out-dir .
1514
touch $@

atom.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl StringCache {
129129
assert!(current != ptr::mut_null());
130130

131131
unsafe {
132-
ptr::read(ptr as *StringCacheEntry);
132+
ptr::read(ptr as *const StringCacheEntry);
133133
heap::deallocate(ptr as *mut u8,
134134
mem::size_of::<StringCacheEntry>(), ENTRY_ALIGNMENT);
135135
}
@@ -252,11 +252,11 @@ impl fmt::Show for Atom {
252252
impl Str for Atom {
253253
fn as_slice<'t>(&'t self) -> &'t str {
254254
let (atom_type, string_len) = self.get_type_and_inline_len();
255-
let ptr = self as *Atom as *u8;
255+
let ptr = self as *const Atom as *const u8;
256256
match atom_type {
257257
Inline => {
258258
unsafe {
259-
let data = ptr.offset(1) as *[u8, ..7];
259+
let data = ptr.offset(1) as *const [u8, ..7];
260260
str::raw::from_utf8((*data).slice_to(string_len))
261261
}
262262
},
@@ -265,7 +265,7 @@ impl Str for Atom {
265265
key.as_slice()
266266
},
267267
Dynamic => {
268-
let hash_value = unsafe { &*(self.data as *StringCacheEntry) };
268+
let hash_value = unsafe { &*(self.data as *const StringCacheEntry) };
269269
hash_value.string.as_slice()
270270
}
271271
}
@@ -279,6 +279,10 @@ impl StrAllocating for Atom {
279279
}
280280

281281
impl PartialOrd for Atom {
282+
fn partial_cmp(&self, other: &Atom) -> Option<Ordering> {
283+
self.data.partial_cmp(&other.data)
284+
}
285+
282286
fn lt(&self, other: &Atom) -> bool {
283287
if self.data == other.data {
284288
return false;
@@ -445,7 +449,7 @@ mod tests {
445449

446450
#[test]
447451
fn test_threads() {
448-
for _ in range(0, 100) {
452+
for _ in range(0u32, 100u32) {
449453
spawn(proc() {
450454
let _ = Atom::from_slice("a dynamic string");
451455
let _ = Atom::from_slice("another string");
@@ -458,12 +462,12 @@ mod tests {
458462
let mut strings0 = vec!();
459463
let mut strings1 = vec!();
460464

461-
for _ in range(0, 1000) {
465+
for _ in range(0u32, 1000u32) {
462466
strings0.push("a");
463467
strings1.push("b");
464468
}
465469

466-
let mut eq_count = 0;
470+
let mut eq_count = 0u32;
467471

468472
b.iter(|| {
469473
for (s0, s1) in strings0.iter().zip(strings1.iter()) {
@@ -479,12 +483,12 @@ mod tests {
479483
let mut atoms0 = vec!();
480484
let mut atoms1 = vec!();
481485

482-
for _ in range(0, 1000) {
486+
for _ in range(0u32, 1000u32) {
483487
atoms0.push(Atom::from_slice("a"));
484488
atoms1.push(Atom::from_slice("b"));
485489
}
486490

487-
let mut eq_count = 0;
491+
let mut eq_count = 0u32;
488492

489493
b.iter(|| {
490494
for (a0, a1) in atoms0.iter().zip(atoms1.iter()) {

lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
#![crate_id = "github.com/mozilla-servo/string-cache#string_cache:0.1"]
11-
#![crate_type = "lib"]
12-
#![crate_type = "dylib"]
10+
#![crate_name = "string_cache"]
1311
#![crate_type = "rlib"]
1412

1513
#![feature(phase, macro_rules)]

static_atoms.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub mod atom {
3333
Div,
3434
}
3535

36-
static STATIC_ATOMS: PhfOrderedMap<StaticAtom> = phf_ordered_map!(
36+
static STATIC_ATOMS: PhfOrderedMap<&'static str, StaticAtom> = phf_ordered_map!(
3737
"" => EmptyString,
3838
"id" => Id,
3939
"class" => Class,
@@ -54,7 +54,7 @@ pub mod atom {
5454
impl FromStr for StaticAtom {
5555
#[inline]
5656
fn from_str(string: &str) -> Option<StaticAtom> {
57-
match STATIC_ATOMS.find(&string) {
57+
match STATIC_ATOMS.find_equiv(&string) {
5858
None => None,
5959
Some(&k) => Some(k)
6060
}
@@ -63,7 +63,7 @@ pub mod atom {
6363

6464
impl StaticAtom {
6565
pub fn as_slice(&self) -> &'static str {
66-
let (string, _) = STATIC_ATOMS.entries().idx(*self as uint).unwrap();
66+
let &(string, _) = STATIC_ATOMS.entries().idx(*self as uint).unwrap();
6767
string
6868
}
6969
}

0 commit comments

Comments
 (0)