Skip to content

Commit 5c10136

Browse files
committed
Use hashbrown replacements for std equivalents
1 parent a8038a8 commit 5c10136

16 files changed

+20
-17
lines changed

ci/check-compiles.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ cargo check
66
cargo doc
77
cargo doc --document-private-items
88
cd fuzz && cargo check --features=stdin_fuzz
9+
cd ../lightning && cargo check --no-default-features --features=no_std

lightning/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ max_level_debug = []
2525
# This is unsafe to use in production because it may result in the counterparty publishing taking our funds.
2626
unsafe_revoked_tx_signing = []
2727
unstable = []
28+
std = []
29+
no_std = ["hashbrown"]
2830

2931
[dependencies]
3032
bitcoin = "0.26"
3133

34+
hashbrown = { version = "0.11", optional = true }
3235
hex = { version = "0.3", optional = true }
3336
regex = { version = "0.1.80", optional = true }
3437

lightning/src/chain/chainmonitor.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use util::events;
3838
use util::events::EventHandler;
3939

4040
use prelude::*;
41-
use std::collections::{HashMap, hash_map};
4241
use std::sync::RwLock;
4342
use core::ops::Deref;
4443

lightning/src/chain/channelmonitor.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ use util::byte_utils;
5252
use util::events::Event;
5353

5454
use prelude::*;
55-
use std::collections::{HashMap, HashSet};
5655
use core::{cmp, mem};
5756
use std::io::Error;
5857
use core::ops::Deref;

lightning/src/chain/keysinterface.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use ln::chan_utils::{HTLCOutputInCommitment, make_funding_redeemscript, ChannelP
3838
use ln::msgs::UnsignedChannelAnnouncement;
3939

4040
use prelude::*;
41-
use std::collections::HashSet;
4241
use core::sync::atomic::{AtomicUsize, Ordering};
4342
use std::io::Error;
4443
use ln::msgs::{DecodeError, MAX_VALUE_MSAT};

lightning/src/chain/onchaintx.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use util::byte_utils;
3434

3535
use prelude::*;
3636
use alloc::collections::BTreeMap;
37-
use std::collections::HashMap;
3837
use core::cmp;
3938
use core::ops::Deref;
4039
use core::mem::replace;

lightning/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,12 @@ pub mod ln;
4444
pub mod routing;
4545

4646
mod prelude {
47+
#[cfg(feature = "no_std")]
48+
extern crate hashbrown;
49+
4750
pub use alloc::{vec, vec::Vec, string::String};
48-
}
51+
#[cfg(not(feature = "no_std"))]
52+
pub use std::collections::{HashMap, HashSet, hash_map};
53+
#[cfg(feature = "no_std")]
54+
pub use self::hashbrown::{HashMap, HashSet, hash_map};
55+
}

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ use ln::functional_test_utils::*;
4141
use util::test_utils;
4242

4343
use prelude::*;
44-
use std::collections::HashMap;
4544
use std::sync::{Arc, Mutex};
4645

4746
// If persister_fail is true, we have the persister return a PermanentFailure

lightning/src/ln/channelmanager.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ use util::errors::APIError;
6464
use prelude::*;
6565
use core::{cmp, mem};
6666
use core::cell::RefCell;
67-
use std::collections::{HashMap, hash_map, HashSet};
6867
use std::io::{Cursor, Read};
6968
use std::sync::{Arc, Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard};
7069
use core::sync::atomic::{AtomicUsize, Ordering};

lightning/src/ln/functional_test_utils.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ use core::cell::RefCell;
4444
use std::rc::Rc;
4545
use std::sync::{Arc, Mutex};
4646
use core::mem;
47-
use std::collections::HashMap;
4847

4948
pub const CHAN_CONFIRM_DEPTH: u32 = 10;
5049

lightning/src/ln/functional_tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ use regex;
5252

5353
use prelude::*;
5454
use alloc::collections::BTreeSet;
55-
use std::collections::{HashMap, HashSet};
5655
use core::default::Default;
5756
use std::sync::{Arc, Mutex};
5857

lightning/src/ln/peer_handler.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use routing::network_graph::NetGraphMsgHandler;
3232

3333
use prelude::*;
3434
use alloc::collections::LinkedList;
35-
use std::collections::{HashMap,hash_map,HashSet};
3635
use std::sync::{Arc, Mutex};
3736
use core::sync::atomic::{AtomicUsize, Ordering};
3837
use core::{cmp, hash, fmt, mem};

lightning/src/ln/reorg_tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use bitcoin::blockdata::block::{Block, BlockHeader};
2323
use bitcoin::hash_types::BlockHash;
2424

2525
use prelude::*;
26-
use std::collections::HashMap;
2726
use core::mem;
2827

2928
use ln::functional_test_utils::*;

lightning/src/routing/router.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use util::logger::Logger;
2424
use prelude::*;
2525
use alloc::collections::BinaryHeap;
2626
use core::cmp;
27-
use std::collections::HashMap;
2827
use core::ops::Deref;
2928

3029
/// A hop in a route
@@ -3838,16 +3837,19 @@ mod tests {
38383837
}
38393838
}
38403839

3840+
#[cfg(feature = "std")]
38413841
pub(super) fn random_init_seed() -> u64 {
38423842
// Because the default HashMap in std pulls OS randomness, we can use it as a (bad) RNG.
3843-
use core::hash::{BuildHasher, Hasher};
3843+
use core::hash::{BuildHasher, Hasher};
38443844
let seed = std::collections::hash_map::RandomState::new().build_hasher().finish();
38453845
println!("Using seed of {}", seed);
38463846
seed
38473847
}
3848+
#[cfg(feature = "std")]
38483849
use util::ser::Readable;
38493850

38503851
#[test]
3852+
#[cfg(feature = "std")]
38513853
fn generate_routes() {
38523854
let mut d = match super::test_utils::get_route_file() {
38533855
Ok(f) => f,
@@ -3875,6 +3877,7 @@ mod tests {
38753877
}
38763878

38773879
#[test]
3880+
#[cfg(feature = "std")]
38783881
fn generate_routes_mpp() {
38793882
let mut d = match super::test_utils::get_route_file() {
38803883
Ok(f) => f,
@@ -3902,7 +3905,7 @@ mod tests {
39023905
}
39033906
}
39043907

3905-
#[cfg(test)]
3908+
#[cfg(all(test, feature = "std"))]
39063909
pub(crate) mod test_utils {
39073910
use std::fs::File;
39083911
/// Tries to open a network graph file, or panics with a URL to fetch it.
@@ -3929,7 +3932,7 @@ pub(crate) mod test_utils {
39293932
}
39303933
}
39313934

3932-
#[cfg(all(test, feature = "unstable"))]
3935+
#[cfg(all(test, feature = "unstable", feature = "std"))]
39333936
mod benches {
39343937
use super::*;
39353938
use util::logger::{Logger, Record};

lightning/src/util/ser.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
1313
use prelude::*;
1414
use std::io::{Read, Write};
15-
use std::collections::HashMap;
1615
use core::hash::Hash;
1716
use std::sync::Mutex;
1817
use core::cmp;

lightning/src/util/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use core::time::Duration;
4242
use std::sync::{Mutex, Arc};
4343
use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
4444
use core::{cmp, mem};
45-
use std::collections::{HashMap, HashSet, VecDeque};
45+
use std::collections::VecDeque;
4646
use chain::keysinterface::InMemorySigner;
4747

4848
pub struct TestVecWriter(pub Vec<u8>);

0 commit comments

Comments
 (0)