Use slice::from_ref and slice::from_mut

This commit is contained in:
Anthony Ramine
2019-09-19 12:23:42 +02:00
committed by Benjamin Bouvier
parent 411545ed9a
commit 178241625c
5 changed files with 9 additions and 24 deletions

View File

@@ -18,7 +18,6 @@ use crate::isa;
use crate::bitset::BitSet;
use crate::entity;
use crate::ref_slice::{ref_slice, ref_slice_mut};
/// Some instructions use an external list of argument values because there is not enough space in
/// the 16-byte `InstructionData` struct. These value lists are stored in a memory pool in

View File

@@ -95,7 +95,6 @@ mod partition_slice;
mod postopt;
mod predicates;
mod redundant_reload_remover;
mod ref_slice;
mod regalloc;
mod result;
mod scoped_hash_map;

View File

@@ -1,18 +0,0 @@
//! Functions for converting a reference into a singleton slice.
//!
//! See also the [`ref_slice` crate](https://crates.io/crates/ref_slice).
//!
//! We define the functions here to avoid external dependencies, and to ensure that they are
//! inlined in this crate.
//!
//! Despite their using an unsafe block, these functions are completely safe.
use core::slice;
pub fn ref_slice<T>(s: &T) -> &[T] {
unsafe { slice::from_raw_parts(s, 1) }
}
pub fn ref_slice_mut<T>(s: &mut T) -> &mut [T] {
unsafe { slice::from_raw_parts_mut(s, 1) }
}

View File

@@ -18,9 +18,9 @@ use crate::entity::{EntityList, ListPool};
use crate::entity::{Keys, PrimaryMap, SecondaryMap};
use crate::ir::{Function, Value};
use crate::packed_option::PackedOption;
use crate::ref_slice::ref_slice;
use core::cmp::Ordering;
use core::fmt;
use core::slice;
use smallvec::SmallVec;
use std::vec::Vec;
@@ -104,7 +104,7 @@ impl VirtRegs {
'a: 'b,
{
self.get(*value)
.map_or_else(|| ref_slice(value), |vr| self.values(vr))
.map_or_else(|| slice::from_ref(value), |vr| self.values(vr))
}
/// Check if `a` and `b` belong to the same congruence class.