implement a map testing benchmark

This involved some other changes:
- add a managed<T> wrapper that makes send_map usable from @-data
- implement map<K,V> for managed<send_map>

Unit tests are coming.
This commit is contained in:
Niko Matsakis
2012-08-21 15:55:17 -07:00
parent 182814ef81
commit bc5eb95222
7 changed files with 367 additions and 10 deletions

View File

@@ -12,6 +12,24 @@ pure fn id<T>(+x: T) -> T { x }
/// Ignores a value.
pure fn ignore<T>(+_x: T) { }
/// Sets `*ptr` to `new_value`, invokes `op()`, and then restores the
/// original value of `*ptr`.
#[inline(always)]
fn with<T: copy, R>(
ptr: &mut T,
+new_value: T,
op: &fn() -> R) -> R
{
// NDM: if swap operator were defined somewhat differently,
// we wouldn't need to copy...
let old_value = *ptr;
*ptr = move new_value;
let result = op();
*ptr = move old_value;
return move result;
}
/**
* Swap the values at two mutable locations of the same type, without
* deinitialising or copying either one.