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

@@ -97,9 +97,14 @@ fn gen_instruction_data(registry: &FormatRegistry, fmt: &mut Formatter) {
fn gen_arguments_method(registry: &FormatRegistry, fmt: &mut Formatter, is_mut: bool) { fn gen_arguments_method(registry: &FormatRegistry, fmt: &mut Formatter, is_mut: bool) {
let (method, mut_, rslice, as_slice) = if is_mut { let (method, mut_, rslice, as_slice) = if is_mut {
("arguments_mut", "mut ", "ref_slice_mut", "as_mut_slice") (
"arguments_mut",
"mut ",
"core::slice::from_mut",
"as_mut_slice",
)
} else { } else {
("arguments", "", "ref_slice", "as_slice") ("arguments", "", "core::slice::from_ref", "as_slice")
}; };
fmtln!( fmtln!(

View File

@@ -18,7 +18,6 @@ use crate::isa;
use crate::bitset::BitSet; use crate::bitset::BitSet;
use crate::entity; 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 /// 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 /// 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 postopt;
mod predicates; mod predicates;
mod redundant_reload_remover; mod redundant_reload_remover;
mod ref_slice;
mod regalloc; mod regalloc;
mod result; mod result;
mod scoped_hash_map; 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::entity::{Keys, PrimaryMap, SecondaryMap};
use crate::ir::{Function, Value}; use crate::ir::{Function, Value};
use crate::packed_option::PackedOption; use crate::packed_option::PackedOption;
use crate::ref_slice::ref_slice;
use core::cmp::Ordering; use core::cmp::Ordering;
use core::fmt; use core::fmt;
use core::slice;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::vec::Vec; use std::vec::Vec;
@@ -104,7 +104,7 @@ impl VirtRegs {
'a: 'b, 'a: 'b,
{ {
self.get(*value) 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. /// Check if `a` and `b` belong to the same congruence class.