-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.h
54 lines (45 loc) · 1.04 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#include "value.h"
#include <algorithm>
#include <cstddef>
#include <cstring>
struct Utils {
// rounds up n to the nearest power of 2
// greater than or equal to n
static inline size_t powerOf2Ceil(size_t n) {
n--;
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
n |= n >> 32;
n++;
return n;
}
static inline void memset64(void *dest, uint64_t value, int size) {
int i;
for(i = 0; i < (size & (~7)); i += 8) {
memcpy(((char *)dest) + i, &value, 8);
}
for(; i < size; i++) {
((char *)dest)[i] = ((char *)&value)[i & 7];
}
}
static inline void fillNil(Value *arr, int size) {
std::fill_n(arr, size, ValueNil);
}
static const size_t MinAllocationSize = 8;
static inline size_t nextAllocationSize(size_t oldcapacity,
size_t targetsize) {
if(targetsize <= MinAllocationSize)
return MinAllocationSize;
if(oldcapacity < 2)
oldcapacity = 2;
size_t s = oldcapacity;
while(s < targetsize) {
s += (s >> 1);
}
return s;
}
};