@@ -47,21 +47,6 @@ pm_serialize_string(pm_parser_t *parser, pm_string_t *string, pm_buffer_t *buffe
4747 }
4848}
4949
50- /**
51- * Serialize a 32-bit integer to the given address always in little-endian.
52- */
53- static void
54- pm_serialize_32(char *address, uint32_t value) {
55- #ifdef PRISM_WORDS_BIGENDIAN
56- address[0] = (char) ((value > > 24) & 0xFF);
57- address[1] = (char) ((value > > 16) & 0xFF);
58- address[2] = (char) ((value > > 8) & 0xFF);
59- address[3] = (char) (value & 0xFF);
60- #else
61- memcpy(address, &value, sizeof(uint32_t));
62- #endif
63- }
64-
6550static void
6651pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
6752 pm_buffer_append_byte(buffer, (uint8_t) PM_NODE_TYPE(node));
@@ -133,7 +118,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
133118 <%- if node . needs_serialized_length? -%>
134119 // serialize length
135120 uint32_t length = pm_sizet_to_u32(buffer-> length - offset - sizeof(uint32_t));
136- pm_serialize_32 (buffer-> value + length_offset, length);
121+ memcpy (buffer-> value + length_offset, & length, sizeof(uint32_t) );
137122 <%- end -%>
138123 break;
139124 }
@@ -246,7 +231,7 @@ pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer)
246231 // Now we're going to serialize the offset of the constant pool back where
247232 // we left space for it.
248233 uint32_t length = pm_sizet_to_u32(buffer-> length);
249- pm_serialize_32 (buffer-> value + offset, length);
234+ memcpy (buffer-> value + offset, & length, sizeof(uint32_t) );
250235
251236 // Now we're going to serialize the constant pool.
252237 offset = buffer-> length;
@@ -273,18 +258,18 @@ pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer)
273258 assert(content_offset < owned _mask);
274259 content_offset | = owned_mask;
275260
276- pm_serialize_32 (buffer-> value + buffer_offset, content_offset);
261+ memcpy (buffer-> value + buffer_offset, & content_offset, 4 );
277262 pm_buffer_append_bytes(buffer, constant-> start, constant-> length);
278263 } else {
279264 // Since this is a shared constant, we are going to write its
280265 // source offset directly into the buffer.
281266 uint32_t source_offset = pm_ptrdifft_to_u32(constant-> start - parser-> start);
282- pm_serialize_32 (buffer-> value + buffer_offset, source_offset);
267+ memcpy (buffer-> value + buffer_offset, & source_offset, 4 );
283268 }
284269
285270 // Now we can write the length of the constant into the buffer.
286271 uint32_t constant_length = pm_sizet_to_u32(constant-> length);
287- pm_serialize_32 (buffer-> value + buffer_offset + 4, constant_length);
272+ memcpy (buffer-> value + buffer_offset + 4, & constant_length, 4 );
288273 }
289274 }
290275}
0 commit comments