Skip to content

Commit f9b2a41

Browse files
committed
Make single macro for both readers and writers
A macro to reduce the amount of duplication again by calling both variants of read and write on all the types. Signed-off-by: Jack Thomson <jackabt@amazon.com>
1 parent bcf0083 commit f9b2a41

File tree

2 files changed

+12
-41
lines changed

2 files changed

+12
-41
lines changed

src/macros.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,13 @@ macro_rules! make_writers {
105105
}
106106
};
107107
}
108+
109+
#[macro_export]
110+
macro_rules! make_read_writers {
111+
($($item:tt),* $(,)?) => {
112+
$(
113+
make_writers!(@single $item);
114+
make_readers!(@single $item);
115+
)*
116+
};
117+
}

src/memory.rs

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::sync::Arc;
1515
use std::time::{Duration, Instant};
1616
use std::{ptr, slice};
1717

18-
use crate::{make_readers, make_writers};
18+
use crate::{make_read_writers, make_readers, make_writers};
1919

2020
const PAGE_SIZE: u32 = 64 * 1024;
2121
const VECTOR_SIZE: usize = 16;
@@ -143,46 +143,7 @@ impl LinearMemory {
143143
-1
144144
}
145145

146-
make_readers!(
147-
(i32),
148-
(i64),
149-
150-
(f32),
151-
(f64),
152-
153-
(i32, i8),
154-
(i32, i16),
155-
156-
(i32, u8),
157-
(i32, u16),
158-
159-
(i64, i8),
160-
(i64, i16),
161-
(i64, i32),
162-
163-
(i64, u8),
164-
(i64, u16),
165-
(i64, u32),
166-
167-
(@atomic i32, AtomicI32),
168-
(@atomic i64, AtomicI64),
169-
170-
(@atomic i32, AtomicI8, i8),
171-
(@atomic i32, AtomicI16, i16),
172-
173-
(@atomic i32, AtomicU8, u8),
174-
(@atomic i32, AtomicU16, u16),
175-
176-
(@atomic i64, AtomicI8, i8),
177-
(@atomic i64, AtomicI16, i16),
178-
(@atomic i64, AtomicI32, i32),
179-
180-
(@atomic i64, AtomicU8, u8),
181-
(@atomic i64, AtomicU16, u16),
182-
(@atomic i64, AtomicU32, u32),
183-
);
184-
185-
make_writers!(
146+
make_read_writers!(
186147
(i32),
187148
(i64),
188149

0 commit comments

Comments
 (0)