on master help sign in
2f823f0iko
.gitignore+4
@@ -1,2 +1,6 @@
1result
1result
2nock/target
2nock/target
3+nock/flamegraph.svg
4+nock/perf.data
5+nock/perf.data.old
6+nock/one.nock
nock/one.nock+1−1
@@ -1 +1 @@
1−A���� �����
1+A�
nock/src/noun.rs+12−3
@@ -1,4 +1,6 @@
1use std::{
1use std::{
2+ borrow::{Borrow, BorrowMut},
3+ cell::Cell,
2 cmp::{self, Ordering},
4 cmp::{self, Ordering},
3 rc::Rc,
5 rc::Rc,
4 str::FromStr,
6 str::FromStr,
@@ -18,7 +20,7 @@ pub enum Noun {
18 Cell {
20 Cell {
19 p: Rc<Noun>,
21 p: Rc<Noun>,
20 q: Rc<Noun>,
22 q: Rc<Noun>,
21− hash: Hash,
23+ hash: Cell<Option<Hash>>,
22 },
24 },
23}
25}
24
26
@@ -151,7 +153,14 @@ impl Noun {
151
153
152 pub fn hash(self: &Self) -> Hash {
154 pub fn hash(self: &Self) -> Hash {
153 match self {
155 match self {
154− Noun::Cell { hash, .. } => *hash,
156+ Noun::Cell { hash, p, q } => match hash.get() {
157+ Some(x) => x.clone(),
158+ None => {
159+ let hash_value = hash_pair(p.clone(), q.clone());
160+ hash.replace(Some(hash_value));
161+ hash_value
162+ }
163+ },
155 Noun::Atom(a) => xxh3_128(&*a.to_bytes_le()),
164 Noun::Atom(a) => xxh3_128(&*a.to_bytes_le()),
156 }
165 }
157 }
166 }
@@ -348,7 +357,7 @@ pub fn cell(p: Rc<Noun>, q: Rc<Noun>) -> Rc<Noun> {
348 Rc::new(Noun::Cell {
357 Rc::new(Noun::Cell {
349 p: p.clone(),
358 p: p.clone(),
350 q: q.clone(),
359 q: q.clone(),
351− hash: hash_pair(p, q),
360+ hash: Cell::new(None),
352 })
361 })
353}
362}
354
363