Skip to content

Commit

Permalink
replace a few old-school constructors for a 0.5% reduction in code size
Browse files Browse the repository at this point in the history
don't waste those 128 KB!
  • Loading branch information
nunoplopes committed Sep 2, 2024
1 parent a3eb2ff commit ef58376
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/ast/pattern/pattern_inference.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ class pattern_inference_cfg : public default_rewriter_cfg {
//
class collect {
struct entry {
expr * m_node;
unsigned m_delta;
entry():m_node(nullptr), m_delta(0) {}
expr * m_node = nullptr;
unsigned m_delta = 0;
entry() = default;
entry(expr * n, unsigned d):m_node(n), m_delta(d) {}
unsigned hash() const {
return hash_u_u(m_node->get_id(), m_delta);
Expand Down
3 changes: 1 addition & 2 deletions src/util/chashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ class chashtable : private HashProc, private EqProc {

protected:
struct cell {
cell * m_next;
cell * m_next = (cell*)1;
T m_data;
cell():m_next(reinterpret_cast<cell*>(1)) {}
bool is_free() const { return GET_TAG(m_next) == 1; }
void mark_free() { m_next = TAG(cell*, m_next, 1); }
void unmark_free() { m_next = UNTAG(cell*, m_next); }
Expand Down
9 changes: 3 additions & 6 deletions src/util/memory_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Revision History:
#pragma once

#include<cstdlib>
#include<memory>
#include<ostream>
#include<iomanip>
#include "util/z3_exception.h"
Expand Down Expand Up @@ -105,18 +106,14 @@ ALLOC_ATTR T * alloc_vect(unsigned sz);
template<typename T>
T * alloc_vect(unsigned sz) {
T * r = static_cast<T*>(memory::allocate(sizeof(T) * sz));
T * curr = r;
for (unsigned i = 0; i < sz; i++, curr++)
new (curr) T();
std::uninitialized_default_construct_n(r, sz);
return r;
}

template<typename T>
void dealloc_vect(T * ptr, unsigned sz) {
if (ptr == nullptr) return;
T * curr = ptr;
for (unsigned i = 0; i < sz; i++, curr++)
curr->~T();
std::destroy_n(ptr, sz);
memory::deallocate(ptr);
}

Expand Down
5 changes: 2 additions & 3 deletions src/util/obj_hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ template<typename Key, typename Value>
class obj_map {
public:
struct key_data {
Key * m_key;
Key * m_key = nullptr;
Value m_value;
key_data():m_key(nullptr), m_value() {
}
key_data() = default;
key_data(Key * k):
m_key(k), m_value() {
}
Expand Down
6 changes: 2 additions & 4 deletions src/util/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ template<typename T>
class symbol_table;

class symbol {
char const * m_data;
char const * m_data = nullptr;

template<typename T>
friend class symbol_table;
Expand All @@ -50,9 +50,7 @@ class symbol {
}
static symbol m_dummy;
public:
symbol():
m_data(nullptr) {
}
symbol() = default;
explicit symbol(char const * d);
explicit symbol(const std::string & str) : symbol(str.c_str()) {}
explicit symbol(unsigned idx):
Expand Down
7 changes: 4 additions & 3 deletions src/util/symbol_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class symbol_table {
symbol m_key;
T m_data;

key_data() {
}
key_data() = default;

explicit key_data(symbol k):
m_key(k) {
Expand All @@ -59,10 +58,12 @@ class symbol_table {
struct hash_entry {
typedef key_data data;
key_data m_data;


#if 0
hash_entry() {
SASSERT(m_data.m_key == symbol::null);
}
#endif

unsigned get_hash() const {
return m_data.m_key.hash();
Expand Down

0 comments on commit ef58376

Please sign in to comment.