Skip to content

Commit ef58376

Browse files
committed
replace a few old-school constructors for a 0.5% reduction in code size
don't waste those 128 KB!
1 parent a3eb2ff commit ef58376

File tree

6 files changed

+15
-21
lines changed

6 files changed

+15
-21
lines changed

src/ast/pattern/pattern_inference.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ class pattern_inference_cfg : public default_rewriter_cfg {
114114
//
115115
class collect {
116116
struct entry {
117-
expr * m_node;
118-
unsigned m_delta;
119-
entry():m_node(nullptr), m_delta(0) {}
117+
expr * m_node = nullptr;
118+
unsigned m_delta = 0;
119+
entry() = default;
120120
entry(expr * n, unsigned d):m_node(n), m_delta(d) {}
121121
unsigned hash() const {
122122
return hash_u_u(m_node->get_id(), m_delta);

src/util/chashtable.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ class chashtable : private HashProc, private EqProc {
5252

5353
protected:
5454
struct cell {
55-
cell * m_next;
55+
cell * m_next = (cell*)1;
5656
T m_data;
57-
cell():m_next(reinterpret_cast<cell*>(1)) {}
5857
bool is_free() const { return GET_TAG(m_next) == 1; }
5958
void mark_free() { m_next = TAG(cell*, m_next, 1); }
6059
void unmark_free() { m_next = UNTAG(cell*, m_next); }

src/util/memory_manager.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Revision History:
1919
#pragma once
2020

2121
#include<cstdlib>
22+
#include<memory>
2223
#include<ostream>
2324
#include<iomanip>
2425
#include "util/z3_exception.h"
@@ -105,18 +106,14 @@ ALLOC_ATTR T * alloc_vect(unsigned sz);
105106
template<typename T>
106107
T * alloc_vect(unsigned sz) {
107108
T * r = static_cast<T*>(memory::allocate(sizeof(T) * sz));
108-
T * curr = r;
109-
for (unsigned i = 0; i < sz; i++, curr++)
110-
new (curr) T();
109+
std::uninitialized_default_construct_n(r, sz);
111110
return r;
112111
}
113112

114113
template<typename T>
115114
void dealloc_vect(T * ptr, unsigned sz) {
116115
if (ptr == nullptr) return;
117-
T * curr = ptr;
118-
for (unsigned i = 0; i < sz; i++, curr++)
119-
curr->~T();
116+
std::destroy_n(ptr, sz);
120117
memory::deallocate(ptr);
121118
}
122119

src/util/obj_hashtable.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ template<typename Key, typename Value>
5656
class obj_map {
5757
public:
5858
struct key_data {
59-
Key * m_key;
59+
Key * m_key = nullptr;
6060
Value m_value;
61-
key_data():m_key(nullptr), m_value() {
62-
}
61+
key_data() = default;
6362
key_data(Key * k):
6463
m_key(k), m_value() {
6564
}

src/util/symbol.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ template<typename T>
2929
class symbol_table;
3030

3131
class symbol {
32-
char const * m_data;
32+
char const * m_data = nullptr;
3333

3434
template<typename T>
3535
friend class symbol_table;
@@ -50,9 +50,7 @@ class symbol {
5050
}
5151
static symbol m_dummy;
5252
public:
53-
symbol():
54-
m_data(nullptr) {
55-
}
53+
symbol() = default;
5654
explicit symbol(char const * d);
5755
explicit symbol(const std::string & str) : symbol(str.c_str()) {}
5856
explicit symbol(unsigned idx):

src/util/symbol_table.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ class symbol_table {
3131
symbol m_key;
3232
T m_data;
3333

34-
key_data() {
35-
}
34+
key_data() = default;
3635

3736
explicit key_data(symbol k):
3837
m_key(k) {
@@ -59,10 +58,12 @@ class symbol_table {
5958
struct hash_entry {
6059
typedef key_data data;
6160
key_data m_data;
62-
61+
62+
#if 0
6363
hash_entry() {
6464
SASSERT(m_data.m_key == symbol::null);
6565
}
66+
#endif
6667

6768
unsigned get_hash() const {
6869
return m_data.m_key.hash();

0 commit comments

Comments
 (0)