diff options
Diffstat (limited to 'components')
-rw-r--r-- | components/gfx/font.rs | 14 | ||||
-rw-r--r-- | components/gfx/font_cache_task.rs | 4 | ||||
-rw-r--r-- | components/layout/css/matching.rs | 9 | ||||
-rw-r--r-- | components/net/http_loader.rs | 2 | ||||
-rw-r--r-- | components/script/parse/html.rs | 2 | ||||
-rw-r--r-- | components/util/persistent_list.rs | 11 | ||||
-rw-r--r-- | components/util/tid.rs | 4 |
7 files changed, 15 insertions, 31 deletions
diff --git a/components/gfx/font.rs b/components/gfx/font.rs index 6fffb845106..b1765e8ae2c 100644 --- a/components/gfx/font.rs +++ b/components/gfx/font.rs @@ -6,9 +6,8 @@ use euclid::{Point2D, Rect, Size2D}; use smallvec::SmallVec; use std::borrow::ToOwned; use std::cell::RefCell; -use std::mem; use std::rc::Rc; -use std::slice; +use std::str; use std::sync::Arc; use style::computed_values::{font_stretch, font_variant, font_weight}; use style::properties::style_structs::Font as FontStyle; @@ -56,12 +55,11 @@ pub trait FontTableTagConversions { impl FontTableTagConversions for FontTableTag { fn tag_to_str(&self) -> String { - unsafe { - let pointer = mem::transmute::<&u32, *const u8>(self); - let mut bytes = slice::from_raw_parts(pointer, 4).to_vec(); - bytes.reverse(); - String::from_utf8_unchecked(bytes) - } + let bytes = [(self >> 24) as u8, + (self >> 16) as u8, + (self >> 8) as u8, + (self >> 0) as u8]; + str::from_utf8(&bytes).unwrap().to_owned() } } diff --git a/components/gfx/font_cache_task.rs b/components/gfx/font_cache_task.rs index 100fde2050f..a9ba770058b 100644 --- a/components/gfx/font_cache_task.rs +++ b/components/gfx/font_cache_task.rs @@ -81,15 +81,11 @@ pub enum Command { Exit(Sender<()>), } -unsafe impl Send for Command {} - /// Reply messages sent from the font cache task to the FontContext caller. pub enum Reply { GetFontTemplateReply(Option<Arc<FontTemplateData>>), } -unsafe impl Send for Reply {} - /// The font cache task itself. It maintains a list of reference counted /// font templates that are currently in use. struct FontCache { diff --git a/components/layout/css/matching.rs b/components/layout/css/matching.rs index 22d66bac70c..ded2d27842b 100644 --- a/components/layout/css/matching.rs +++ b/components/layout/css/matching.rs @@ -23,13 +23,12 @@ use selectors::parser::PseudoElement; use selectors::{Element}; use std::borrow::ToOwned; use std::hash::{Hash, Hasher}; -use std::mem; use std::slice::Iter; use std::sync::Arc; use std::sync::mpsc::Sender; use string_cache::{Atom, Namespace}; use style::node::TElementAttributes; -use style::properties::{ComputedValues, cascade}; +use style::properties::{ComputedValues, cascade, PropertyDeclaration}; use style::selector_matching::{Stylist, DeclarationBlock}; use util::arc_ptr_eq; use util::cache::{LRUCache, SimpleHashCache}; @@ -128,9 +127,9 @@ impl<'a> PartialEq<ApplicableDeclarationsCacheEntry> for ApplicableDeclarationsC impl<'a> Hash for ApplicableDeclarationsCacheQuery<'a> { fn hash<H: Hasher>(&self, state: &mut H) { for declaration in self.declarations { - let ptr: usize = unsafe { - mem::transmute_copy(declaration) - }; + // Each declaration contians an Arc, which is a stable + // pointer; we use that for hashing and equality. + let ptr = &*declaration.declarations as *const Vec<PropertyDeclaration>; ptr.hash(state); } } diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index e34910ea31d..031fa5ec8f4 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -105,7 +105,7 @@ fn read_block<R: Read>(reader: &mut R) -> Result<ReadResult, ()> { match reader.read(&mut buf) { Ok(len) if len > 0 => { - unsafe { buf.set_len(len); } + buf.truncate(len); Ok(ReadResult::Payload(buf)) } Ok(_) => Ok(ReadResult::EOF), diff --git a/components/script/parse/html.rs b/components/script/parse/html.rs index 7a0ae327008..8aec2e816e4 100644 --- a/components/script/parse/html.rs +++ b/components/script/parse/html.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#![allow(unsafe_code, unrooted_must_root)] +#![allow(unrooted_must_root)] use document_loader::DocumentLoader; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; diff --git a/components/util/persistent_list.rs b/components/util/persistent_list.rs index 55d2b6cd2fd..9043fe76e54 100644 --- a/components/util/persistent_list.rs +++ b/components/util/persistent_list.rs @@ -4,7 +4,6 @@ //! A persistent, thread-safe singly-linked list. -use std::mem; use std::sync::Arc; pub struct PersistentList<T> { @@ -81,15 +80,7 @@ impl<'a, T> Iterator for PersistentListIterator<'a, T> where T: Send + Sync + 's fn next(&mut self) -> Option<&'a T> { let entry = match self.entry { None => return None, - Some(entry) => { - // This `transmute` is necessary to ensure that the lifetimes of the next entry and - // this entry match up; the compiler doesn't know this, but we do because of the - // reference counting behavior of `Arc`. - unsafe { - mem::transmute::<&'a PersistentListEntry<T>, - &'static PersistentListEntry<T>>(entry) - } - } + Some(entry) => entry, }; let value = &entry.value; self.entry = match entry.next { diff --git a/components/util/tid.rs b/components/util/tid.rs index a07508cdb2b..ebed22881b3 100644 --- a/components/util/tid.rs +++ b/components/util/tid.rs @@ -6,7 +6,7 @@ use std::cell::RefCell; use std::rc::Rc; use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; -static mut next_tid: AtomicUsize = ATOMIC_USIZE_INIT; +static NEXT_TID: AtomicUsize = ATOMIC_USIZE_INIT; thread_local!(static TASK_LOCAL_TID: Rc<RefCell<Option<usize>>> = Rc::new(RefCell::new(None))); @@ -15,7 +15,7 @@ pub fn tid() -> usize { TASK_LOCAL_TID.with(|ref k| { let ret = match *k.borrow() { - None => unsafe { next_tid.fetch_add(1, Ordering::SeqCst) }, + None => NEXT_TID.fetch_add(1, Ordering::SeqCst), Some(x) => x, }; |