mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Auto merge of #7523 - eefriedman:unnecessary-unsafe, r=SimonSapin
Fix up some unnecessary uses of `unsafe`. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7523) <!-- Reviewable:end -->
This commit is contained in:
commit
be9a9ffda1
8 changed files with 208 additions and 226 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue