New internal string format:
* maximum size of a string is 2^32-1 now by default on a 64 bits system (can be increased using M_USE_STRING_LARGE_INDEX if needed). * This reduce consumption of a string_t from 24 bytes to 16 bytes. * Change the stack representation of a string, so that it lets 15 allocated bytes for the user even in 64 bytes mode. For 32 bits system, it increases to 15 allocated byte for stack representation. * synthetic performance benchmark shows a little bit of decrease of performance. But performance in real application shows a significant increase (probably due to the reduced size of the type). *Augment test suite to be sure to test all corner cases of the new representaiton.
This commit is contained in:
1 parent
bf59c53921
commit
67e9c8ff06
3 files changed
+198
-96
No files matched your search
+10
-6
@@ -71,15 +71,17 @@ m_ser1al_json_write_float(m_serial_write_t serial, const long double data, const
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_json_write_string(m_serial_write_t serial, const char data[], size_t length)
|
||||
{
|
||||
M_ASSERT(length == (m_str1ng_size_t) length);
|
||||
M_ASSERT_SLOW(length == strlen(data) );
|
||||
FILE *f = (FILE *)serial->data[0].p;
|
||||
M_ASSERT(f != NULL && data != NULL);
|
||||
/* HACK: Build dummy string to reuse m_string_out_str */
|
||||
m_string_t v2;
|
||||
uintptr_t ptr = (uintptr_t) data;
|
||||
v2->u.heap.size = length;
|
||||
v2->u.heap.alloc = length + 1;
|
||||
v2->ptr = (char*)ptr;
|
||||
v2->u.heap.size = (m_str1ng_size_t) length;
|
||||
v2->u.heap.alloc[sizeof(m_str1ng_size_t)-2] = 1;
|
||||
v2->u.heap.alloc[sizeof(m_str1ng_size_t)-1] = 31;
|
||||
v2->u.heap.ptr = (char*)ptr;
|
||||
m_string_out_str(f, v2);
|
||||
return M_UNLIKELY(ferror(f)) ? m_core_serial_fail() : M_SERIAL_OK_DONE;
|
||||
}
|
||||
@@ -620,15 +622,17 @@ m_ser1al_str_json_write_float(m_serial_write_t serial, const long double data, c
|
||||
M_INLINE m_serial_return_code_t
|
||||
m_ser1al_str_json_write_string(m_serial_write_t serial, const char data[], size_t length)
|
||||
{
|
||||
M_ASSERT(length == (m_str1ng_size_t) length);
|
||||
M_ASSERT_SLOW(length == strlen(data) );
|
||||
struct m_string_s *f = (struct m_string_s *)serial->data[0].p;
|
||||
M_ASSERT(f != NULL && data != NULL);
|
||||
/* HACK: Build dummy string to reuse m_string_get_str */
|
||||
m_string_t v2;
|
||||
uintptr_t ptr = (uintptr_t) data;
|
||||
v2->u.heap.size = length;
|
||||
v2->u.heap.alloc = length + 1;
|
||||
v2->ptr = (char*)ptr;
|
||||
v2->u.heap.size = (m_str1ng_size_t) length;
|
||||
v2->u.heap.alloc[sizeof(m_str1ng_size_t)-2] = 1;
|
||||
v2->u.heap.alloc[sizeof(m_str1ng_size_t)-1] = 31;
|
||||
v2->u.heap.ptr = (char*)ptr;
|
||||
m_string_get_str(f, v2, true);
|
||||
return M_SERIAL_OK_DONE;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user