Skip to content

Commit bb43a4e

Browse files
committed
Merge remote-tracking branch 'upstream/pr/57'
2 parents c63f564 + ce93ce5 commit bb43a4e

File tree

8 files changed

+89
-86
lines changed

8 files changed

+89
-86
lines changed

macros/src/atom/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,4 @@ macro_rules! qualname (($ns:tt, $local:tt) => (
139139
ns: ns!($ns),
140140
local: atom!($local),
141141
}
142-
))
142+
));

macros/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,33 @@
1010
#![crate_name="string_cache_macros"]
1111
#![crate_type="dylib"]
1212

13-
#![feature(macro_rules, plugin_registrar, quote, phase)]
13+
#![feature(plugin_registrar, quote, int_uint, box_syntax)]
1414
#![allow(unused_imports)] // for quotes
1515

1616
extern crate core;
1717
extern crate syntax;
1818
extern crate rustc;
1919

20-
#[phase(plugin)]
20+
#[macro_use]
2121
extern crate lazy_static;
2222

2323
use rustc::plugin::Registry;
2424

2525
macro_rules! bail ( ($cx:expr, $sp:expr, $msg:expr) => ({
2626
$cx.span_err($sp, $msg);
2727
return ::syntax::ext::base::DummyResult::any($sp);
28-
}))
28+
}));
2929

3030
macro_rules! bail_if ( ($e:expr, $cx:expr, $sp:expr, $msg:expr) => (
3131
if $e { bail!($cx, $sp, $msg) }
32-
))
32+
));
3333

3434
macro_rules! expect ( ($cx:expr, $sp:expr, $e:expr, $msg:expr) => (
3535
match $e {
3636
Some(x) => x,
3737
None => bail!($cx, $sp, $msg),
3838
}
39-
))
39+
));
4040

4141
mod atom;
4242

shared/repr.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#![allow(dead_code, unused_imports)]
1515

1616
use core::{mem, raw, intrinsics};
17-
use core::option::{Option, Some, None};
18-
use core::ptr::RawPtr;
19-
use core::slice::{SlicePrelude, AsSlice};
17+
use core::option::Option::{self, Some, None};
18+
use core::ptr::PtrExt;
19+
use core::slice::{AsSlice, SliceExt};
2020
use core::slice::bytes;
2121

2222
pub use self::UnpackedAtom::{Dynamic, Inline, Static};
@@ -26,7 +26,7 @@ pub const DYNAMIC_TAG: u8 = 0u8;
2626
pub const INLINE_TAG: u8 = 1u8; // len in upper nybble
2727
pub const STATIC_TAG: u8 = 2u8;
2828

29-
pub const MAX_INLINE_LEN: uint = 7;
29+
pub const MAX_INLINE_LEN: usize = 7;
3030

3131
// Atoms use a compact representation which fits this enum in a single u64.
3232
// Inlining avoids actually constructing the unpacked representation in memory.
@@ -35,13 +35,13 @@ pub enum UnpackedAtom {
3535
Dynamic(*mut ()),
3636

3737
/// Length + bytes of string.
38-
Inline(u8, [u8, ..7]),
38+
Inline(u8, [u8; 7]),
3939

4040
/// Index in static interning table.
4141
Static(u32),
4242
}
4343

44-
const STATIC_SHIFT_BITS: uint = 32;
44+
const STATIC_SHIFT_BITS: usize = 32;
4545

4646
#[inline(always)]
4747
unsafe fn inline_atom_slice(x: &u64) -> raw::Slice<u8> {
@@ -69,7 +69,7 @@ impl UnpackedAtom {
6969
n
7070
}
7171
Inline(len, buf) => {
72-
debug_assert!((len as uint) <= MAX_INLINE_LEN);
72+
debug_assert!((len as usize) <= MAX_INLINE_LEN);
7373
let mut data: u64 = (INLINE_TAG as u64) | ((len as u64) << 4);
7474
{
7575
let dest: &mut [u8] = mem::transmute(inline_atom_slice(&mut data));
@@ -89,9 +89,9 @@ impl UnpackedAtom {
8989
DYNAMIC_TAG => Dynamic(data as *mut ()),
9090
STATIC_TAG => Static((data >> STATIC_SHIFT_BITS) as u32),
9191
INLINE_TAG => {
92-
let len = ((data & 0xf0) >> 4) as uint;
92+
let len = ((data & 0xf0) >> 4) as usize;
9393
debug_assert!(len <= MAX_INLINE_LEN);
94-
let mut buf: [u8, ..7] = [0, ..7];
94+
let mut buf: [u8; 7] = [0; 7];
9595
let src: &[u8] = mem::transmute(inline_atom_slice(&data));
9696
bytes::copy_memory(buf.as_mut_slice(), src);
9797
Inline(len as u8, buf)

src/atom/bench.rs

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -44,37 +44,37 @@ macro_rules! check_type (($name:ident, $x:expr, $p:pat) => (
4444
_ => panic!("atom has wrong type"),
4545
}
4646
}
47-
))
47+
));
4848

4949
macro_rules! bench_tiny_op (($name:ident, $op:ident, $ctor_x:expr, $ctor_y:expr) => (
5050
#[bench]
5151
fn $name(b: &mut Bencher) {
5252
const n: uint = 1000;
53-
let xs = Vec::from_elem(n, $ctor_x);
54-
let ys = Vec::from_elem(n, $ctor_y);
53+
let xs: Vec<_> = repeat($ctor_x).take(n).collect();
54+
let ys: Vec<_> = repeat($ctor_y).take(n).collect();
5555

5656
b.iter(|| {
5757
for (x, y) in xs.iter().zip(ys.iter()) {
5858
black_box(x.$op(y));
5959
}
6060
});
6161
}
62-
))
62+
));
6363

6464
macro_rules! bench_one (
65-
(x_static $x:expr, $y:expr) => (check_type!(check_type_x, $x, Static(..)));
66-
(x_inline $x:expr, $y:expr) => (check_type!(check_type_x, $x, Inline(..)));
67-
(x_dynamic $x:expr, $y:expr) => (check_type!(check_type_x, $x, Dynamic(..)));
68-
(y_static $x:expr, $y:expr) => (check_type!(check_type_y, $y, Static(..)));
69-
(y_inline $x:expr, $y:expr) => (check_type!(check_type_y, $y, Inline(..)));
70-
(y_dynamic $x:expr, $y:expr) => (check_type!(check_type_y, $y, Dynamic(..)));
71-
(is_static $x:expr, $y:expr) => (bench_one!(x_static $x, $y) bench_one!(y_static $x, $y));
72-
(is_inline $x:expr, $y:expr) => (bench_one!(x_inline $x, $y) bench_one!(y_inline $x, $y));
73-
(is_dynamic $x:expr, $y:expr) => (bench_one!(x_dynamic $x, $y) bench_one!(y_dynamic $x, $y));
74-
75-
(eq $x:expr, $_y:expr) => (bench_tiny_op!(eq_x_1000, eq, $x, $x));
76-
(ne $x:expr, $y:expr) => (bench_tiny_op!(ne_x_1000, ne, $x, $y));
77-
(lt $x:expr, $y:expr) => (bench_tiny_op!(lt_x_1000, lt, $x, $y));
65+
(x_static $x:expr, $y:expr) => (check_type!(check_type_x, $x, Static(..)););
66+
(x_inline $x:expr, $y:expr) => (check_type!(check_type_x, $x, Inline(..)););
67+
(x_dynamic $x:expr, $y:expr) => (check_type!(check_type_x, $x, Dynamic(..)););
68+
(y_static $x:expr, $y:expr) => (check_type!(check_type_y, $y, Static(..)););
69+
(y_inline $x:expr, $y:expr) => (check_type!(check_type_y, $y, Inline(..)););
70+
(y_dynamic $x:expr, $y:expr) => (check_type!(check_type_y, $y, Dynamic(..)););
71+
(is_static $x:expr, $y:expr) => (bench_one!(x_static $x, $y); bench_one!(y_static $x, $y););
72+
(is_inline $x:expr, $y:expr) => (bench_one!(x_inline $x, $y); bench_one!(y_inline $x, $y););
73+
(is_dynamic $x:expr, $y:expr) => (bench_one!(x_dynamic $x, $y); bench_one!(y_dynamic $x, $y););
74+
75+
(eq $x:expr, $_y:expr) => (bench_tiny_op!(eq_x_1000, eq, $x, $x););
76+
(ne $x:expr, $y:expr) => (bench_tiny_op!(ne_x_1000, ne, $x, $y););
77+
(lt $x:expr, $y:expr) => (bench_tiny_op!(lt_x_1000, lt, $x, $y););
7878

7979
(intern $x:expr, $_y:expr) => (
8080
#[bench]
@@ -122,7 +122,7 @@ macro_rules! bench_one (
122122
});
123123
}
124124
);
125-
)
125+
);
126126

127127
macro_rules! bench_all (
128128
([ $($which:ident)+ ] for $name:ident = $x:expr, $y:expr) => (
@@ -135,61 +135,62 @@ macro_rules! bench_all (
135135
use collections::vec::Vec;
136136
use test::{Bencher, black_box};
137137
use std::string::ToString;
138+
use std::iter::repeat;
138139

139140
use atom::Atom;
140141
use atom::repr::{Static, Inline, Dynamic};
141142

142143
use super::mk;
143144

144145
$(
145-
bench_one!($which $x, $y)
146+
bench_one!($which $x, $y);
146147
)+
147148
}
148149
);
149-
)
150+
);
150151

151152
pub const longer_dynamic_a: &'static str
152153
= "Thee Silver Mt. Zion Memorial Orchestra & Tra-La-La Band";
153154
pub const longer_dynamic_b: &'static str
154155
= "Thee Silver Mt. Zion Memorial Orchestra & Tra-La-La Ban!";
155156

156-
bench_all!([eq ne lt clone_string] for short_string = "e", "f")
157-
bench_all!([eq ne lt clone_string] for medium_string = "xyzzy01", "xyzzy02")
157+
bench_all!([eq ne lt clone_string] for short_string = "e", "f");
158+
bench_all!([eq ne lt clone_string] for medium_string = "xyzzy01", "xyzzy02");
158159
bench_all!([eq ne lt clone_string]
159-
for longer_string = super::longer_dynamic_a, super::longer_dynamic_b)
160+
for longer_string = super::longer_dynamic_a, super::longer_dynamic_b);
160161

161162
bench_all!([eq ne intern as_slice clone is_static lt]
162-
for static_atom = atom!(a), atom!(b))
163+
for static_atom = atom!(a), atom!(b));
163164

164165
bench_all!([intern as_slice clone is_inline]
165-
for short_inline_atom = mk("e"), mk("f"))
166+
for short_inline_atom = mk("e"), mk("f"));
166167

167168
bench_all!([eq ne intern as_slice clone is_inline lt]
168-
for medium_inline_atom = mk("xyzzy01"), mk("xyzzy02"))
169+
for medium_inline_atom = mk("xyzzy01"), mk("xyzzy02"));
169170

170171
bench_all!([intern as_slice clone is_dynamic]
171-
for min_dynamic_atom = mk("xyzzy001"), mk("xyzzy002"))
172+
for min_dynamic_atom = mk("xyzzy001"), mk("xyzzy002"));
172173

173174
bench_all!([eq ne intern as_slice clone is_dynamic lt]
174-
for longer_dynamic_atom = mk(super::longer_dynamic_a), mk(super::longer_dynamic_b))
175+
for longer_dynamic_atom = mk(super::longer_dynamic_a), mk(super::longer_dynamic_b));
175176

176177
bench_all!([intern as_slice clone is_static]
177-
for static_at_runtime = mk("a"), mk("b"))
178+
for static_at_runtime = mk("a"), mk("b"));
178179

179180
bench_all!([ne lt x_static y_inline]
180-
for static_vs_inline = atom!(a), mk("f"))
181+
for static_vs_inline = atom!(a), mk("f"));
181182

182183
bench_all!([ne lt x_static y_dynamic]
183-
for static_vs_dynamic = atom!(a), mk(super::longer_dynamic_b))
184+
for static_vs_dynamic = atom!(a), mk(super::longer_dynamic_b));
184185

185186
bench_all!([ne lt x_inline y_dynamic]
186-
for inline_vs_dynamic = mk("e"), mk(super::longer_dynamic_b))
187+
for inline_vs_dynamic = mk("e"), mk(super::longer_dynamic_b));
187188

188189
macro_rules! bench_rand ( ($name:ident, $len:expr) => (
189190
#[bench]
190191
fn $name(b: &mut Bencher) {
191192
use std::{str, rand};
192-
use std::slice::{SlicePrelude, AsSlice};
193+
use std::slice::{AsSlice, SliceExt};
193194
use std::rand::Rng;
194195

195196
let mut gen = rand::weak_rng();
@@ -200,19 +201,19 @@ macro_rules! bench_rand ( ($name:ident, $len:expr) => (
200201
// I measured the overhead of random string generation
201202
// as about 3-12% at one point.
202203

203-
let mut buf: [u8, ..$len] = [0, ..$len];
204+
let mut buf: [u8; $len] = [0; $len];
204205
gen.fill_bytes(buf.as_mut_slice());
205206
for n in buf.iter_mut() {
206207
// shift into printable ASCII
207208
*n = (*n % 0x40) + 0x20;
208209
}
209-
let s = unsafe { str::raw::from_utf8(buf.as_slice()) };
210+
let s = str::from_utf8(buf.as_slice()).unwrap();
210211
black_box(Atom::from_slice(s));
211212
});
212213
}
213-
))
214+
));
214215

215-
bench_rand!(intern_rand_008, 8)
216-
bench_rand!(intern_rand_032, 32)
217-
bench_rand!(intern_rand_128, 128)
218-
bench_rand!(intern_rand_512, 512)
216+
bench_rand!(intern_rand_008, 8);
217+
bench_rand!(intern_rand_032, 32);
218+
bench_rand!(intern_rand_128, 128);
219+
bench_rand!(intern_rand_512, 512);

0 commit comments

Comments
 (0)