Mercurial > lbo > hg > leveldb-rs
changeset 110:c48c912aee64
Convert transmute_copy() uses to simple casts
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sun, 13 Nov 2016 14:55:00 +0100 |
parents | 0b7271ebf175 |
children | 74096ebd4337 290af663edcf |
files | src/cache.rs src/skipmap.rs |
diffstat | 2 files changed, 15 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/cache.rs Sat Oct 15 15:43:23 2016 +0200 +++ b/src/cache.rs Sun Nov 13 14:55:00 2016 +0100 @@ -1,5 +1,5 @@ use std::collections::HashMap; -use std::mem::{swap, replace, transmute_copy}; +use std::mem::{swap, replace}; // No clone, no copy! That asserts that an LRUHandle exists only once. type LRUHandle<T> = *mut LRUNode<T>; @@ -35,9 +35,9 @@ let mut new = Box::new(LRUNode { data: Some(elem), next: None, - prev: unsafe { Some(transmute_copy(&&self.head)) }, + prev: Some(&mut self.head as *mut LRUNode<T>), }); - let newp = unsafe { transmute_copy(&new.as_mut()) }; + let newp = new.as_mut() as *mut LRUNode<T>; // Set up the node after the new one self.head.next.as_mut().unwrap().prev = Some(newp); @@ -51,9 +51,9 @@ let mut new = Box::new(LRUNode { data: Some(elem), next: None, - prev: unsafe { Some(transmute_copy(&&self.head)) }, + prev: Some(&mut self.head as *mut LRUNode<T>), }); - let newp = unsafe { transmute_copy(&new.as_mut()) }; + let newp = new.as_mut() as *mut LRUNode<T>; // Set tail self.head.prev = Some(newp);
--- a/src/skipmap.rs Sat Oct 15 15:43:23 2016 +0200 +++ b/src/skipmap.rs Sun Nov 13 14:55:00 2016 +0100 @@ -1,7 +1,7 @@ use types::{Comparator, StandardComparator, LdbIterator}; use rand::{Rng, SeedableRng, StdRng}; use std::cmp::Ordering; -use std::mem::{replace, size_of, transmute_copy}; +use std::mem::{replace, size_of}; const MAX_HEIGHT: usize = 12; const BRANCHING_FACTOR: u32 = 4; @@ -82,7 +82,7 @@ /// Returns None if the given key lies past the greatest key in the table. fn get_greater_or_equal<'a>(&'a self, key: &[u8]) -> Option<&'a Node> { // Start at the highest skip link of the head node, and work down from there - let mut current: *const Node = unsafe { transmute_copy(&self.head.as_ref()) }; + let mut current = self.head.as_ref() as *const Node; let mut level = self.head.skips.len() - 1; loop { @@ -125,7 +125,7 @@ /// Returns None if no smaller key was found. fn get_next_smaller<'a>(&'a self, key: &[u8]) -> Option<&'a Node> { // Start at the highest skip link of the head node, and work down from there - let mut current: *const Node = unsafe { transmute_copy(&self.head.as_ref()) }; + let mut current = self.head.as_ref() as *const Node; let mut level = self.head.skips.len() - 1; loop { @@ -168,7 +168,7 @@ let mut prevs: Vec<Option<*mut Node>> = Vec::with_capacity(new_height); let mut level = MAX_HEIGHT - 1; - let mut current: *mut Node = unsafe { transmute_copy(&self.head.as_mut()) }; + let mut current = self.head.as_mut() as *mut Node; // Initialize all prevs entries with *head prevs.resize(new_height, Some(current)); @@ -209,7 +209,7 @@ key: key, value: val, }); - let newp = unsafe { transmute_copy(&(new.as_mut())) }; + let newp = new.as_mut() as *mut Node; for i in 0..new_height { if let Some(prev) = prevs[i] { @@ -235,13 +235,13 @@ pub fn iter<'a>(&'a self) -> SkipMapIter<'a, C> { SkipMapIter { map: self, - current: unsafe { transmute_copy(&self.head.as_ref()) }, + current: self.head.as_ref() as *const Node, } } /// Runs through the skipmap and prints everything including addresses fn dbg_print(&self) { - let mut current: *const Node = unsafe { transmute_copy(&self.head.as_ref()) }; + let mut current = self.head.as_ref() as *const Node; loop { unsafe { println!("{:?} {:?}/{:?} - {:?}", @@ -271,7 +271,7 @@ // we first go to the next element, then return that -- in order to skip the head node unsafe { (*self.current).next.as_ref().map(|next| { - self.current = transmute_copy(&next.as_ref()); + self.current = next.as_ref() as *const Node; ((*self.current).key.as_slice(), (*self.current).value.as_slice()) }) } @@ -285,7 +285,7 @@ } fn seek(&mut self, key: &[u8]) { if let Some(node) = self.map.get_greater_or_equal(key) { - self.current = unsafe { transmute_copy(&node) } + self.current = node as *const Node } else { self.reset(); } @@ -304,7 +304,7 @@ // Going after the original implementation here; we just seek to the node before current(). if let Some(current) = self.current() { if let Some(prev) = self.map.get_next_smaller(current.0) { - self.current = unsafe { transmute_copy(&prev) }; + self.current = prev as *const Node; if !prev.key.is_empty() { return Some(unsafe { (&(*self.current).key, &(*self.current).value) });