You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2017/02/04 17:53:27 UTC

[4/7] lucy git commit: Remove indirection from NumUtil_encode_bigend_* arg

Remove indirection from NumUtil_encode_bigend_* arg


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/cd3e363e
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/cd3e363e
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/cd3e363e

Branch: refs/heads/master
Commit: cd3e363e19c6aac5a6680604db21ec493838e8f7
Parents: 2c43cf0
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri Feb 3 14:51:38 2017 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Fri Feb 3 14:53:11 2017 +0100

----------------------------------------------------------------------
 core/Lucy/Index/SortFieldWriter.c     |  4 ++--
 core/Lucy/Store/OutStream.c           | 24 ++++++++++--------------
 core/Lucy/Util/NumberUtils.cfh        | 19 +++++++------------
 test/Lucy/Test/Util/TestNumberUtils.c | 20 ++++++++++----------
 4 files changed, 29 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/cd3e363e/core/Lucy/Index/SortFieldWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortFieldWriter.c b/core/Lucy/Index/SortFieldWriter.c
index 85fb411..b5fef00 100644
--- a/core/Lucy/Index/SortFieldWriter.c
+++ b/core/Lucy/Index/SortFieldWriter.c
@@ -240,13 +240,13 @@ S_write_ord(void *ords, int32_t width, int32_t doc_id, int32_t ord) {
         case 16: {
                 uint8_t *bytes = (uint8_t*)ords;
                 bytes += (size_t)doc_id * sizeof(uint16_t);
-                NumUtil_encode_bigend_u16((uint16_t)ord, &bytes);
+                NumUtil_encode_bigend_u16((uint16_t)ord, bytes);
             }
             break;
         case 32: {
                 uint8_t *bytes = (uint8_t*)ords;
                 bytes += (size_t)doc_id * sizeof(uint32_t);
-                NumUtil_encode_bigend_u32((uint32_t)ord, &bytes);
+                NumUtil_encode_bigend_u32((uint32_t)ord, bytes);
             }
             break;
         default:

http://git-wip-us.apache.org/repos/asf/lucy/blob/cd3e363e/core/Lucy/Store/OutStream.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/OutStream.c b/core/Lucy/Store/OutStream.c
index cd10165..4d83947 100644
--- a/core/Lucy/Store/OutStream.c
+++ b/core/Lucy/Store/OutStream.c
@@ -236,9 +236,8 @@ SI_write_u32(OutStream *self, OutStreamIVARS *ivars, uint32_t value) {
 #ifdef CHY_BIG_END
     SI_write_bytes(self, ivars, &value, 4);
 #else
-    char  buf[4];
-    char *buf_copy = buf;
-    NumUtil_encode_bigend_u32(value, &buf_copy);
+    char buf[4];
+    NumUtil_encode_bigend_u32(value, buf);
     SI_write_bytes(self, ivars, buf, 4);
 #endif
 }
@@ -258,9 +257,8 @@ SI_write_u64(OutStream *self, OutStreamIVARS *ivars, uint64_t value) {
 #ifdef CHY_BIG_END
     SI_write_bytes(self, ivars, &value, 8);
 #else
-    char  buf[sizeof(uint64_t)];
-    char *buf_copy = buf;
-    NumUtil_encode_bigend_u64(value, &buf_copy);
+    char buf[sizeof(uint64_t)];
+    NumUtil_encode_bigend_u64(value, buf);
     SI_write_bytes(self, ivars, buf, sizeof(uint64_t));
 #endif
 }
@@ -278,19 +276,17 @@ OutStream_Write_U64_IMP(OutStream *self, uint64_t value) {
 void
 OutStream_Write_F32_IMP(OutStream *self, float value) {
     OutStreamIVARS *const ivars = OutStream_IVARS(self);
-    char  buf[sizeof(float)];
-    char *buf_copy = buf;
-    NumUtil_encode_bigend_f32(value, &buf_copy);
-    SI_write_bytes(self, ivars, buf_copy, sizeof(float));
+    char buf[sizeof(float)];
+    NumUtil_encode_bigend_f32(value, buf);
+    SI_write_bytes(self, ivars, buf, sizeof(float));
 }
 
 void
 OutStream_Write_F64_IMP(OutStream *self, double value) {
     OutStreamIVARS *const ivars = OutStream_IVARS(self);
-    char  buf[sizeof(double)];
-    char *buf_copy = buf;
-    NumUtil_encode_bigend_f64(value, &buf_copy);
-    SI_write_bytes(self, ivars, buf_copy, sizeof(double));
+    char buf[sizeof(double)];
+    NumUtil_encode_bigend_f64(value, buf);
+    SI_write_bytes(self, ivars, buf, sizeof(double));
 }
 
 void

http://git-wip-us.apache.org/repos/asf/lucy/blob/cd3e363e/core/Lucy/Util/NumberUtils.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/NumberUtils.cfh b/core/Lucy/Util/NumberUtils.cfh
index 5ecf7fa..caf4e82 100644
--- a/core/Lucy/Util/NumberUtils.cfh
+++ b/core/Lucy/Util/NumberUtils.cfh
@@ -215,8 +215,7 @@ lucy_NumUtil_is_bigend() {
 }
 
 static CFISH_INLINE void
-lucy_NumUtil_encode_bigend_u16(uint16_t value, void *dest_ptr) {
-    uint8_t *dest = *(uint8_t**)dest_ptr;
+lucy_NumUtil_encode_bigend_u16(uint16_t value, void *dest) {
     if (!lucy_NumUtil_is_bigend()) {
         value = ((value & 0xFF00) >> 8) | ((value & 0x00FF) << 8);
     }
@@ -224,8 +223,7 @@ lucy_NumUtil_encode_bigend_u16(uint16_t value, void *dest_ptr) {
 }
 
 static CFISH_INLINE void
-lucy_NumUtil_encode_bigend_u32(uint32_t value, void *dest_ptr) {
-    uint8_t *dest = *(uint8_t**)dest_ptr;
+lucy_NumUtil_encode_bigend_u32(uint32_t value, void *dest) {
     if (!lucy_NumUtil_is_bigend()) {
         value =
             ((value & 0xFF000000) >> 24) |
@@ -237,8 +235,7 @@ lucy_NumUtil_encode_bigend_u32(uint32_t value, void *dest_ptr) {
 }
 
 static CFISH_INLINE void
-lucy_NumUtil_encode_bigend_u64(uint64_t value, void *dest_ptr) {
-    uint8_t *dest = *(uint8_t**)dest_ptr;
+lucy_NumUtil_encode_bigend_u64(uint64_t value, void *dest) {
     if (!lucy_NumUtil_is_bigend()) {
         value =
             ((value & 0xFF00000000000000) >> 56) |
@@ -285,28 +282,26 @@ lucy_NumUtil_decode_bigend_u64(const void *source) {
 }
 
 static CFISH_INLINE void
-lucy_NumUtil_encode_bigend_f32(float value, void *dest_ptr) {
-    uint8_t *dest = *(uint8_t**)dest_ptr;
+lucy_NumUtil_encode_bigend_f32(float value, void *dest) {
     if (lucy_NumUtil_is_bigend()) {
         memcpy(dest, &value, sizeof(float));
     }
     else {
         union { float f; uint32_t u32; } duo;
         duo.f = value;
-        lucy_NumUtil_encode_bigend_u32(duo.u32, &dest);
+        lucy_NumUtil_encode_bigend_u32(duo.u32, dest);
     }
 }
 
 static CFISH_INLINE void
-lucy_NumUtil_encode_bigend_f64(double value, void *dest_ptr) {
-    uint8_t *dest = *(uint8_t**)dest_ptr;
+lucy_NumUtil_encode_bigend_f64(double value, void *dest) {
     if (lucy_NumUtil_is_bigend()) {
         memcpy(dest, &value, sizeof(double));
     }
     else {
         union { double d; uint64_t u64; } duo;
         duo.d = value;
-        lucy_NumUtil_encode_bigend_u64(duo.u64, &dest);
+        lucy_NumUtil_encode_bigend_u64(duo.u64, dest);
     }
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/cd3e363e/test/Lucy/Test/Util/TestNumberUtils.c
----------------------------------------------------------------------
diff --git a/test/Lucy/Test/Util/TestNumberUtils.c b/test/Lucy/Test/Util/TestNumberUtils.c
index f9cf3a1..f906e07 100644
--- a/test/Lucy/Test/Util/TestNumberUtils.c
+++ b/test/Lucy/Test/Util/TestNumberUtils.c
@@ -305,7 +305,7 @@ test_bigend_u16(TestBatchRunner *runner) {
     char     *target    = encoded;
 
     for (size_t i = 0; i < count; i++) {
-        NumUtil_encode_bigend_u16((uint16_t)ints[i], &target);
+        NumUtil_encode_bigend_u16((uint16_t)ints[i], target);
         target += sizeof(uint16_t);
     }
     target = encoded;
@@ -316,7 +316,7 @@ test_bigend_u16(TestBatchRunner *runner) {
     }
 
     target = encoded;
-    NumUtil_encode_bigend_u16(1, &target);
+    NumUtil_encode_bigend_u16(1, target);
     TEST_INT_EQ(runner, encoded[0], 0, "Truly big-endian u16");
     TEST_INT_EQ(runner, encoded[1], 1, "Truly big-endian u16");
 
@@ -335,7 +335,7 @@ test_bigend_u32(TestBatchRunner *runner) {
 
     for (size_t i = 0; i < count; i++) {
         ints[i] = (uint32_t)ints[i];
-        NumUtil_encode_bigend_u32((uint32_t)ints[i], &target);
+        NumUtil_encode_bigend_u32((uint32_t)ints[i], target);
         target += sizeof(uint32_t);
     }
     target = encoded;
@@ -346,7 +346,7 @@ test_bigend_u32(TestBatchRunner *runner) {
     }
 
     target = encoded;
-    NumUtil_encode_bigend_u32(1, &target);
+    NumUtil_encode_bigend_u32(1, target);
     TEST_INT_EQ(runner, encoded[0], 0, "Truly big-endian u32");
     TEST_INT_EQ(runner, encoded[3], 1, "Truly big-endian u32");
 
@@ -364,7 +364,7 @@ test_bigend_u64(TestBatchRunner *runner) {
     char     *target    = encoded;
 
     for (size_t i = 0; i < count; i++) {
-        NumUtil_encode_bigend_u64(ints[i], &target);
+        NumUtil_encode_bigend_u64(ints[i], target);
         target += sizeof(uint64_t);
     }
     target = encoded;
@@ -375,7 +375,7 @@ test_bigend_u64(TestBatchRunner *runner) {
     }
 
     target = encoded;
-    NumUtil_encode_bigend_u64(1, &target);
+    NumUtil_encode_bigend_u64(1, target);
     TEST_INT_EQ(runner, encoded[0], 0, "Truly big-endian");
     TEST_INT_EQ(runner, encoded[7], 1, "Truly big-endian");
 
@@ -393,7 +393,7 @@ test_bigend_f32(TestBatchRunner *runner) {
     uint8_t *target    = encoded;
 
     for (size_t i = 0; i < count; i++) {
-        NumUtil_encode_bigend_f32(source[i], &target);
+        NumUtil_encode_bigend_f32(source[i], target);
         target += sizeof(float);
     }
     target = encoded;
@@ -404,7 +404,7 @@ test_bigend_f32(TestBatchRunner *runner) {
     }
 
     target = encoded;
-    NumUtil_encode_bigend_f32(-2.0f, &target);
+    NumUtil_encode_bigend_f32(-2.0f, target);
     TEST_INT_EQ(runner, (encoded[0] & 0x80), 0x80,
                 "Truly big-endian (IEEE 754 sign bit set for negative number)");
     TEST_INT_EQ(runner, encoded[0], 0xC0,
@@ -427,7 +427,7 @@ test_bigend_f64(TestBatchRunner *runner) {
     uint8_t *target    = encoded;
 
     for (size_t i = 0; i < count; i++) {
-        NumUtil_encode_bigend_f64(source[i], &target);
+        NumUtil_encode_bigend_f64(source[i], target);
         target += sizeof(double);
     }
     target = encoded;
@@ -438,7 +438,7 @@ test_bigend_f64(TestBatchRunner *runner) {
     }
 
     target = encoded;
-    NumUtil_encode_bigend_f64(-2.0, &target);
+    NumUtil_encode_bigend_f64(-2.0, target);
     TEST_INT_EQ(runner, (encoded[0] & 0x80), 0x80,
                 "Truly big-endian (IEEE 754 sign bit set for negative number)");
     TEST_INT_EQ(runner, encoded[0], 0xC0,