MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / memrevifle

Function memrevifle

deps/lua/src/lua_cmsgpack.c:69–85  ·  view source on GitHub ↗

Reverse memory bytes if arch is little endian. Given the conceptual * simplicity of the Lua build system we prefer check for endianess at runtime. * The performance difference should be acceptable. */

Source from the content-addressed store, hash-verified

67 * simplicity of the Lua build system we prefer check for endianess at runtime.
68 * The performance difference should be acceptable. */
69void memrevifle(void *ptr, size_t len) {
70 unsigned char *p = (unsigned char *)ptr,
71 *e = (unsigned char *)p+len-1,
72 aux;
73 int test = 1;
74 unsigned char *testp = (unsigned char*) &test;
75
76 if (testp[0] == 0) return; /* Big endian, nothing to do. */
77 len /= 2;
78 while(len--) {
79 aux = *p;
80 *p = *e;
81 *e = aux;
82 p++;
83 e--;
84 }
85}
86
87/* ---------------------------- String buffer ----------------------------------
88 * This is a simple implementation of string buffers. The only operation

Callers 2

mp_encode_doubleFunction · 0.85
lua_cmsgpack.cFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected