Преглед на файлове

cleanup, round to 2 multiple without loop

Kajetan Johannes Hammerle преди 1 месец
родител
ревизия
478150a167
променени са 8 файла, в които са добавени 11 реда и са изтрити 12 реда
  1. 11 4
      src/HashMap.c
  2. 0 2
      src/View.c
  3. 0 1
      test/modules/BitArrayTests.c
  4. 0 1
      test/modules/BoxTests.c
  5. 0 1
      test/modules/HashMapTests.c
  6. 0 1
      test/modules/PlaneTests.c
  7. 0 1
      test/modules/QueueTests.c
  8. 0 1
      test/modules/ViewTests.c

+ 11 - 4
src/HashMap.c

@@ -9,9 +9,16 @@ size_t hashString(const char* key) {
 }
 
 size_t roundUp2(size_t n) {
-    size_t w = 1;
-    while(w < n) {
-        w *= 2;
+    n -= n != 0;
+    n |= n >> 1;
+    n |= n >> 2;
+    n |= n >> 4;
+    n |= n >> 8;
+    if(sizeof(n) >= 4) {
+        n |= n >> 16;
     }
-    return w;
+    if(sizeof(n) >= 8) {
+        n |= n >> 32;
+    }
+    return n + 1;
 }

+ 0 - 2
src/View.c

@@ -2,8 +2,6 @@
 
 #include "core/Generic.h"
 
-#define CV3(a, b, c) (&(Vector3){{a, b, c}})
-
 void initView(View* v) {
     *v = (View){0};
 }

+ 0 - 1
test/modules/BitArrayTests.c

@@ -1,6 +1,5 @@
 #include "../Tests.h"
 #include "core/BitArray.h"
-#include "core/ToString.h"
 
 static void testSetRead() {
     BitArray bits;

+ 0 - 1
test/modules/BoxTests.c

@@ -1,6 +1,5 @@
 #include "../Tests.h"
 #include "core/Box.h"
-#include "core/ToString.h"
 
 static void testInit() {
     Box box = BOX;

+ 0 - 1
test/modules/HashMapTests.c

@@ -1,7 +1,6 @@
 #include "../Tests.h"
 #include "core/HashMap.h"
 #include "core/ToString.h"
-#include "core/Utility.h"
 
 HASHMAP(size_t, size_t, Size)
 

+ 0 - 1
test/modules/PlaneTests.c

@@ -1,6 +1,5 @@
 #include "../Tests.h"
 #include "core/Plane.h"
-#include "core/ToString.h"
 
 static const float eps = 0.0001f;
 

+ 0 - 1
test/modules/QueueTests.c

@@ -1,7 +1,6 @@
 #include "../Tests.h"
 #include "core/Queue.h"
 #include "core/ToString.h"
-#include "core/Utility.h"
 
 QUEUE(size_t, Size)
 QUEUE_SOURCE(size_t, Size)

+ 0 - 1
test/modules/ViewTests.c

@@ -1,5 +1,4 @@
 #include "../Tests.h"
-#include "core/ToString.h"
 #include "core/View.h"
 
 static void testFromAngles() {