sp-std removal from substrate/primitives (#3274)

This PR removes sp-std crate from substrate/primitives sub-directories.

For now crates that have `pub use` of sp-std or export macros that would
necessitate users of the macros to `extern crate alloc` have been
excluded from this PR.

There should be no breaking changes in this PR.

---------

Co-authored-by: Koute <koute@users.noreply.github.com>
This commit is contained in:
Squirrel
2024-03-18 05:29:35 +00:00
committed by GitHub
parent 6b1179f13b
commit 1b5f4243d1
110 changed files with 254 additions and 278 deletions
@@ -20,16 +20,14 @@
use super::{Extrinsics, StorageKey, StorageValue};
#[cfg(not(feature = "std"))]
use sp_std::collections::btree_set::BTreeSet as Set;
use alloc::collections::btree_set::BTreeSet as Set;
#[cfg(feature = "std")]
use std::collections::HashSet as Set;
use crate::warn;
use alloc::collections::{btree_map::BTreeMap, btree_set::BTreeSet};
use core::hash::Hash;
use smallvec::SmallVec;
use sp_std::{
collections::{btree_map::BTreeMap, btree_set::BTreeSet},
hash::Hash,
};
const PROOF_OVERLAY_NON_EMPTY: &str = "\
An OverlayValue is always created with at least one transaction and dropped as soon
@@ -225,7 +223,7 @@ impl<K: Ord + Hash + Clone, V> OverlayedMap<K, V> {
/// This changeset might be created when there are already open transactions.
/// We need to catch up here so that the child is at the same transaction depth.
pub fn spawn_child(&self) -> Self {
use sp_std::iter::repeat;
use core::iter::repeat;
Self {
changes: Default::default(),
dirty_keys: repeat(Set::new()).take(self.transaction_depth()).collect(),
@@ -242,7 +240,7 @@ impl<K: Ord + Hash + Clone, V> OverlayedMap<K, V> {
/// Get an optional reference to the value stored for the specified key.
pub fn get<Q>(&self, key: &Q) -> Option<&OverlayedEntry<V>>
where
K: sp_std::borrow::Borrow<Q>,
K: core::borrow::Borrow<Q>,
Q: Ord + ?Sized,
{
self.changes.get(key)
@@ -448,7 +446,7 @@ impl OverlayedChangeSet {
/// Get the iterator over all changes that follow the supplied `key`.
pub fn changes_after(&self, key: &[u8]) -> impl Iterator<Item = (&[u8], &OverlayedValue)> {
use sp_std::ops::Bound;
use core::ops::Bound;
let range = (Bound::Excluded(key), Bound::Unbounded);
self.changes.range::<[u8], _>(range).map(|(k, v)| (k.as_slice(), v))
}
@@ -22,6 +22,7 @@ mod offchain;
use self::changeset::OverlayedChangeSet;
use crate::{backend::Backend, stats::StateMachineStats, BackendTransaction, DefaultError};
use alloc::{collections::btree_set::BTreeSet, vec::Vec};
use codec::{Decode, Encode};
use hash_db::Hasher;
pub use offchain::OffchainOverlayedChanges;
@@ -31,12 +32,13 @@ use sp_core::{
};
#[cfg(feature = "std")]
use sp_externalities::{Extension, Extensions};
#[cfg(not(feature = "std"))]
use sp_std::collections::btree_map::BTreeMap as Map;
use sp_std::{collections::btree_set::BTreeSet, vec::Vec};
use sp_trie::{empty_child_trie_root, LayoutV1};
#[cfg(not(feature = "std"))]
use alloc::collections::btree_map::BTreeMap as Map;
#[cfg(feature = "std")]
use std::collections::{hash_map::Entry as MapEntry, HashMap as Map};
#[cfg(feature = "std")]
use std::{
any::{Any, TypeId},
@@ -136,7 +138,7 @@ impl<H: Hasher> Clone for OverlayedChanges<H> {
}
}
impl<H: Hasher> sp_std::fmt::Debug for OverlayedChanges<H> {
impl<H: Hasher> core::fmt::Debug for OverlayedChanges<H> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("OverlayedChanges")
.field("top", &self.top)
@@ -259,7 +261,7 @@ impl<H: Hasher> Clone for StorageTransactionCache<H> {
}
}
impl<H: Hasher> sp_std::fmt::Debug for StorageTransactionCache<H> {
impl<H: Hasher> core::fmt::Debug for StorageTransactionCache<H> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let mut debug = f.debug_struct("StorageTransactionCache");
@@ -572,7 +574,7 @@ impl<H: Hasher> OverlayedChanges<H> {
},
};
use sp_std::mem::take;
use core::mem::take;
let main_storage_changes = take(&mut self.top).drain_commited();
let child_storage_changes = take(&mut self.children)
.into_iter()
@@ -777,7 +779,7 @@ where
K: Ord,
F: FnMut(&K, &mut V) -> bool,
{
let old = sp_std::mem::replace(map, Map::default());
let old = core::mem::replace(map, Map::default());
for (k, mut v) in old.into_iter() {
if f(&k, &mut v) {
map.insert(k, v);
@@ -18,8 +18,8 @@
//! Overlayed changes for offchain indexing.
use super::changeset::OverlayedMap;
use alloc::vec::Vec;
use sp_core::offchain::OffchainOverlayedChange;
use sp_std::prelude::Vec;
/// In-memory storage for offchain workers recoding changes for the actual offchain storage
/// implementation.
@@ -48,7 +48,7 @@ impl OffchainOverlayedChanges {
/// Drain all elements of changeset.
pub fn drain(&mut self) -> impl Iterator<Item = OffchainOverlayedChangesItemOwned> {
sp_std::mem::take(self).into_iter()
core::mem::take(self).into_iter()
}
/// Remove a key and its associated value from the offchain database.