Skip to content

Commit f6e1f5f

Browse files
authored
RUST-364 Cache unique process value for oids (#214)
1 parent 1636078 commit f6e1f5f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/oid.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,16 @@ impl ObjectId {
153153

154154
// Generate a random 5-byte array.
155155
fn gen_process_id() -> [u8; 5] {
156-
let rng = thread_rng().gen_range(0, MAX_U24) as u32;
157-
let mut buf: [u8; 5] = [0; 5];
158-
buf[0..4].copy_from_slice(&rng.to_be_bytes());
159-
buf
156+
lazy_static! {
157+
static ref BUF: [u8; 5] = {
158+
let rng = thread_rng().gen_range(0, MAX_U24) as u32;
159+
let mut buf: [u8; 5] = [0; 5];
160+
buf[0..4].copy_from_slice(&rng.to_be_bytes());
161+
buf
162+
};
163+
}
164+
165+
*BUF
160166
}
161167

162168
// Gets an incremental 3-byte count.

0 commit comments

Comments
 (0)