Skip to content

Commit bae03f3

Browse files
committed
---
yaml --- r: 65021 b: refs/heads/snap-stage3 c: c852a5b h: refs/heads/master i: 65019: cad6fcf v: v3
1 parent 4c562ac commit bae03f3

File tree

8 files changed

+62
-64
lines changed

8 files changed

+62
-64
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 2765811cb6530eb73c5450bd25e915e67bd512cf
4+
refs/heads/snap-stage3: c852a5bb681d08796959818470ed5233bfa69edc
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/hashmap.rs

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,7 @@ enum SearchResult {
6161

6262
#[inline]
6363
fn resize_at(capacity: uint) -> uint {
64-
((capacity as float) * 3. / 4.) as uint
65-
}
66-
67-
/// Creates a new hash map with the specified capacity.
68-
pub fn linear_map_with_capacity<K:Eq + Hash,V>(
69-
initial_capacity: uint) -> HashMap<K, V> {
70-
let mut r = rand::task_rng();
71-
linear_map_with_capacity_and_keys(r.gen(), r.gen(),
72-
initial_capacity)
73-
}
74-
75-
fn linear_map_with_capacity_and_keys<K:Eq + Hash,V>(
76-
k0: u64, k1: u64,
77-
initial_capacity: uint) -> HashMap<K, V> {
78-
let cap = num::max(INITIAL_CAPACITY, initial_capacity);
79-
HashMap {
80-
k0: k0, k1: k1,
81-
resize_at: resize_at(cap),
82-
size: 0,
83-
buckets: vec::from_fn(cap, |_| None)
84-
}
64+
(capacity * 3) / 4
8565
}
8666

8767
impl<K:Hash + Eq,V> HashMap<K, V> {
@@ -352,10 +332,28 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
352332
HashMap::with_capacity(INITIAL_CAPACITY)
353333
}
354334

355-
/// Create an empty HashMap with space for at least `n` elements in
356-
/// the hash table.
335+
/// Create an empty HashMap with space for at least `capacity`
336+
/// elements in the hash table.
357337
pub fn with_capacity(capacity: uint) -> HashMap<K, V> {
358-
linear_map_with_capacity(capacity)
338+
let mut r = rand::task_rng();
339+
HashMap::with_capacity_and_keys(r.gen(), r.gen(), capacity)
340+
}
341+
342+
/// Create an empty HashMap with space for at least `capacity`
343+
/// elements, using `k0` and `k1` as the keys.
344+
///
345+
/// Warning: `k0` and `k1` are normally randomly generated, and
346+
/// are designed to allow HashMaps to be resistant to attacks that
347+
/// cause many collisions and very poor performance. Setting them
348+
/// manually using this function can expose a DoS attack vector.
349+
pub fn with_capacity_and_keys(k0: u64, k1: u64, capacity: uint) -> HashMap<K, V> {
350+
let cap = num::max(INITIAL_CAPACITY, capacity);
351+
HashMap {
352+
k0: k0, k1: k1,
353+
resize_at: resize_at(cap),
354+
size: 0,
355+
buckets: vec::from_fn(cap, |_| None)
356+
}
359357
}
360358

361359
/// Reserve space for at least `n` elements in the hash table.
@@ -844,7 +842,7 @@ mod test_map {
844842

845843
#[test]
846844
fn test_insert_conflicts() {
847-
let mut m = linear_map_with_capacity(4);
845+
let mut m = HashMap::with_capacity(4);
848846
assert!(m.insert(1, 2));
849847
assert!(m.insert(5, 3));
850848
assert!(m.insert(9, 4));
@@ -855,7 +853,7 @@ mod test_map {
855853

856854
#[test]
857855
fn test_conflict_remove() {
858-
let mut m = linear_map_with_capacity(4);
856+
let mut m = HashMap::with_capacity(4);
859857
assert!(m.insert(1, 2));
860858
assert!(m.insert(5, 3));
861859
assert!(m.insert(9, 4));
@@ -866,7 +864,7 @@ mod test_map {
866864

867865
#[test]
868866
fn test_is_empty() {
869-
let mut m = linear_map_with_capacity(4);
867+
let mut m = HashMap::with_capacity(4);
870868
assert!(m.insert(1, 2));
871869
assert!(!m.is_empty());
872870
assert!(m.remove(&1));
@@ -927,7 +925,7 @@ mod test_map {
927925

928926
#[test]
929927
fn test_iterate() {
930-
let mut m = linear_map_with_capacity(4);
928+
let mut m = HashMap::with_capacity(4);
931929
foreach i in range(0u, 32) {
932930
assert!(m.insert(i, i*2));
933931
}

branches/snap-stage3/src/libsyntax/ext/build.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ pub trait AstBuilder {
7676
fn stmt_let(&self, sp: span, mutbl: bool, ident: ast::ident, ex: @ast::expr) -> @ast::stmt;
7777

7878
// blocks
79-
fn block(&self, span: span, stmts: ~[@ast::stmt], expr: Option<@ast::expr>) -> ast::Block;
80-
fn block_expr(&self, expr: @ast::expr) -> ast::Block;
81-
fn block_all(&self, span: span,
82-
view_items: ~[ast::view_item],
83-
stmts: ~[@ast::stmt],
84-
expr: Option<@ast::expr>) -> ast::Block;
79+
fn blk(&self, span: span, stmts: ~[@ast::stmt], expr: Option<@ast::expr>) -> ast::Block;
80+
fn blk_expr(&self, expr: @ast::expr) -> ast::Block;
81+
fn blk_all(&self, span: span,
82+
view_items: ~[ast::view_item],
83+
stmts: ~[@ast::stmt],
84+
expr: Option<@ast::expr>) -> ast::Block;
8585

8686
// expressions
8787
fn expr(&self, span: span, node: ast::expr_) -> @ast::expr;
@@ -105,7 +105,7 @@ pub trait AstBuilder {
105105
fn expr_method_call(&self, span: span,
106106
expr: @ast::expr, ident: ast::ident,
107107
args: ~[@ast::expr]) -> @ast::expr;
108-
fn expr_block(&self, b: ast::Block) -> @ast::expr;
108+
fn expr_blk(&self, b: ast::Block) -> @ast::expr;
109109

110110
fn field_imm(&self, span: span, name: ident, e: @ast::expr) -> ast::Field;
111111
fn expr_struct(&self, span: span, path: ast::Path, fields: ~[ast::Field]) -> @ast::expr;
@@ -387,18 +387,18 @@ impl AstBuilder for @ExtCtxt {
387387
@respan(sp, ast::stmt_decl(@decl, self.next_id()))
388388
}
389389

390-
fn block(&self, span: span, stmts: ~[@ast::stmt], expr: Option<@expr>) -> ast::Block {
391-
self.block_all(span, ~[], stmts, expr)
390+
fn blk(&self, span: span, stmts: ~[@ast::stmt], expr: Option<@expr>) -> ast::Block {
391+
self.blk_all(span, ~[], stmts, expr)
392392
}
393393

394-
fn block_expr(&self, expr: @ast::expr) -> ast::Block {
395-
self.block_all(expr.span, ~[], ~[], Some(expr))
394+
fn blk_expr(&self, expr: @ast::expr) -> ast::Block {
395+
self.blk_all(expr.span, ~[], ~[], Some(expr))
396396
}
397-
fn block_all(&self,
398-
span: span,
399-
view_items: ~[ast::view_item],
400-
stmts: ~[@ast::stmt],
401-
expr: Option<@ast::expr>) -> ast::Block {
397+
fn blk_all(&self,
398+
span: span,
399+
view_items: ~[ast::view_item],
400+
stmts: ~[@ast::stmt],
401+
expr: Option<@ast::expr>) -> ast::Block {
402402
ast::Block {
403403
view_items: view_items,
404404
stmts: stmts,
@@ -474,7 +474,7 @@ impl AstBuilder for @ExtCtxt {
474474
self.expr(span,
475475
ast::expr_method_call(self.next_id(), expr, ident, ~[], args, ast::NoSugar))
476476
}
477-
fn expr_block(&self, b: ast::Block) -> @ast::expr {
477+
fn expr_blk(&self, b: ast::Block) -> @ast::expr {
478478
self.expr(b.span, ast::expr_block(b))
479479
}
480480
fn field_imm(&self, span: span, name: ident, e: @ast::expr) -> ast::Field {
@@ -577,7 +577,7 @@ impl AstBuilder for @ExtCtxt {
577577
ast::arm {
578578
pats: pats,
579579
guard: None,
580-
body: self.block_expr(expr)
580+
body: self.blk_expr(expr)
581581
}
582582
}
583583

@@ -591,8 +591,8 @@ impl AstBuilder for @ExtCtxt {
591591

592592
fn expr_if(&self, span: span,
593593
cond: @ast::expr, then: @ast::expr, els: Option<@ast::expr>) -> @ast::expr {
594-
let els = els.map(|x| self.expr_block(self.block_expr(*x)));
595-
self.expr(span, ast::expr_if(cond, self.block_expr(then), els))
594+
let els = els.map(|x| self.expr_blk(self.blk_expr(*x)));
595+
self.expr(span, ast::expr_if(cond, self.blk_expr(then), els))
596596
}
597597

598598
fn lambda_fn_decl(&self, span: span, fn_decl: ast::fn_decl, blk: ast::Block) -> @ast::expr {
@@ -618,23 +618,23 @@ impl AstBuilder for @ExtCtxt {
618618
}
619619

620620
fn lambda_expr(&self, span: span, ids: ~[ast::ident], expr: @ast::expr) -> @ast::expr {
621-
self.lambda(span, ids, self.block_expr(expr))
621+
self.lambda(span, ids, self.blk_expr(expr))
622622
}
623623
fn lambda_expr_0(&self, span: span, expr: @ast::expr) -> @ast::expr {
624-
self.lambda0(span, self.block_expr(expr))
624+
self.lambda0(span, self.blk_expr(expr))
625625
}
626626
fn lambda_expr_1(&self, span: span, expr: @ast::expr, ident: ast::ident) -> @ast::expr {
627-
self.lambda1(span, self.block_expr(expr), ident)
627+
self.lambda1(span, self.blk_expr(expr), ident)
628628
}
629629

630630
fn lambda_stmts(&self, span: span, ids: ~[ast::ident], stmts: ~[@ast::stmt]) -> @ast::expr {
631-
self.lambda(span, ids, self.block(span, stmts, None))
631+
self.lambda(span, ids, self.blk(span, stmts, None))
632632
}
633633
fn lambda_stmts_0(&self, span: span, stmts: ~[@ast::stmt]) -> @ast::expr {
634-
self.lambda0(span, self.block(span, stmts, None))
634+
self.lambda0(span, self.blk(span, stmts, None))
635635
}
636636
fn lambda_stmts_1(&self, span: span, stmts: ~[@ast::stmt], ident: ast::ident) -> @ast::expr {
637-
self.lambda1(span, self.block(span, stmts, None), ident)
637+
self.lambda1(span, self.blk(span, stmts, None), ident)
638638
}
639639

640640
fn arg(&self, span: span, ident: ast::ident, ty: ast::Ty) -> ast::arg {

branches/snap-stage3/src/libsyntax/ext/deriving/encodable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn encodable_substructure(cx: @ExtCtxt, span: span,
178178
~[cx.expr_str(span,
179179
cx.str_of(substr.type_ident)),
180180
blk]);
181-
cx.expr_block(cx.block(span, ~[me], Some(ret)))
181+
cx.expr_blk(cx.blk(span, ~[me], Some(ret)))
182182
}
183183

184184
_ => cx.bug("expected Struct or EnumMatching in deriving(Encodable)")

branches/snap-stage3/src/libsyntax/ext/deriving/generic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ impl<'self> MethodDef<'self> {
527527

528528
let method_ident = cx.ident_of(self.name);
529529
let fn_decl = cx.fn_decl(args, ret_type);
530-
let body_block = cx.block_expr(body);
530+
let body_block = cx.blk_expr(body);
531531

532532

533533
// Create the method.

branches/snap-stage3/src/libsyntax/ext/deriving/to_str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn to_str_substructure(cx: @ExtCtxt, span: span,
7979
}
8080
push(cx.expr_str(span, end));
8181
82-
cx.expr_block(cx.block(span, stmts, Some(cx.expr_ident(span, buf))))
82+
cx.expr_blk(cx.blk(span, stmts, Some(cx.expr_ident(span, buf))))
8383
}
8484
};
8585

branches/snap-stage3/src/libsyntax/ext/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,5 +323,5 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span,
323323
nargs, expected_nargs));
324324
}
325325

326-
cx.expr_block(cx.block(fmt_sp, stms, Some(buf())))
326+
cx.expr_blk(cx.blk(fmt_sp, stms, Some(buf())))
327327
}

branches/snap-stage3/src/libsyntax/ext/quote.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -705,11 +705,11 @@ fn expand_tts(cx: @ExtCtxt,
705705
id_ext("tt"),
706706
cx.expr_vec_uniq(sp, ~[]));
707707

708-
cx.expr_block(
709-
cx.block_all(sp, uses,
710-
~[stmt_let_sp,
711-
stmt_let_tt] + mk_tts(cx, sp, tts),
712-
Some(cx.expr_ident(sp, id_ext("tt")))))
708+
cx.expr_blk(
709+
cx.blk_all(sp, uses,
710+
~[stmt_let_sp,
711+
stmt_let_tt] + mk_tts(cx, sp, tts),
712+
Some(cx.expr_ident(sp, id_ext("tt")))))
713713
}
714714

715715
fn expand_parse_call(cx: @ExtCtxt,

0 commit comments

Comments
 (0)