@@ -77,6 +77,15 @@ pub extern "C" fn dealloc(pointer: *mut c_void, capacity: usize) {
77
77
}
78
78
}
79
79
80
+ macro_rules! push_u8s {
81
+ ( $u8s: ident in $output: ident) => (
82
+ $output. push( $u8s. 0 ) ;
83
+ $output. push( $u8s. 1 ) ;
84
+ $output. push( $u8s. 2 ) ;
85
+ $output. push( $u8s. 3 ) ;
86
+ )
87
+ }
88
+
80
89
#[ no_mangle]
81
90
pub extern "C" fn root ( pointer : * mut u8 , length : usize ) -> * mut u8 {
82
91
let input = unsafe { slice:: from_raw_parts ( pointer, length) } ;
@@ -87,10 +96,7 @@ pub extern "C" fn root(pointer: *mut u8, length: usize) -> *mut u8 {
87
96
if let Ok ( ( _remaining, nodes) ) = gutenberg_post_parser:: root ( input) {
88
97
let nodes_length = u32_to_u8s ( nodes. len ( ) as u32 ) ;
89
98
90
- output. push ( nodes_length. 0 ) ;
91
- output. push ( nodes_length. 1 ) ;
92
- output. push ( nodes_length. 2 ) ;
93
- output. push ( nodes_length. 3 ) ;
99
+ push_u8s ! ( nodes_length in output) ;
94
100
95
101
for node in nodes {
96
102
into_bytes ( & node, & mut output) ;
@@ -125,10 +131,7 @@ fn into_bytes<'a>(node: &Node<'a>, output: &mut Vec<u8>) {
125
131
126
132
output. push ( node_type) ;
127
133
output. push ( name_length as u8 ) ;
128
- output. push ( attributes_length_as_u8s. 0 ) ;
129
- output. push ( attributes_length_as_u8s. 1 ) ;
130
- output. push ( attributes_length_as_u8s. 2 ) ;
131
- output. push ( attributes_length_as_u8s. 3 ) ;
134
+ push_u8s ! ( attributes_length_as_u8s in output) ;
132
135
output. push ( number_of_children as u8 ) ;
133
136
134
137
output. extend ( name. 0 ) ;
@@ -149,16 +152,10 @@ fn into_bytes<'a>(node: &Node<'a>, output: &mut Vec<u8>) {
149
152
Node :: Phrase ( phrase) => {
150
153
let node_type = 2u8 ;
151
154
let phrase_length = phrase. len ( ) ;
152
-
153
- output. push ( node_type) ;
154
-
155
155
let phrase_length_as_u8s = u32_to_u8s ( phrase_length as u32 ) ;
156
156
157
- output. push ( phrase_length_as_u8s. 0 ) ;
158
- output. push ( phrase_length_as_u8s. 1 ) ;
159
- output. push ( phrase_length_as_u8s. 2 ) ;
160
- output. push ( phrase_length_as_u8s. 3 ) ;
161
-
157
+ output. push ( node_type) ;
158
+ push_u8s ! ( phrase_length_as_u8s in output) ;
162
159
output. extend ( phrase) ;
163
160
}
164
161
}
0 commit comments