3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-02-17 14:21:45 +00:00

Remove copies (#8583)

This commit is contained in:
Nuno Lopes 2026-02-11 18:14:36 +00:00 committed by GitHub
parent 0da28c6d19
commit 836a76c78a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 38 additions and 51 deletions

View file

@ -29,13 +29,13 @@ Revision History:
*/
template<typename T>
class obj_hash_entry {
T * m_ptr = nullptr;
T * m_ptr = nullptr;
public:
typedef T * data;
unsigned get_hash() const { return m_ptr->hash(); }
bool is_free() const { return m_ptr == nullptr; }
bool is_deleted() const { return m_ptr == reinterpret_cast<T *>(1); }
bool is_used() const { return m_ptr != reinterpret_cast<T *>(0) && m_ptr != reinterpret_cast<T *>(1); }
bool is_used() const { return m_ptr != nullptr && m_ptr != reinterpret_cast<T *>(1); }
T * get_data() const { return m_ptr; }
T * & get_data() { return m_ptr; }
void set_data(T * d) { m_ptr = d; }
@ -50,21 +50,18 @@ public:
obj_hashtable(unsigned initial_capacity = DEFAULT_HASHTABLE_INITIAL_CAPACITY):
core_hashtable<obj_hash_entry<T>, obj_ptr_hash<T>, ptr_eq<T> >(initial_capacity) {}
obj_hashtable(const obj_hashtable & source) = default;
obj_hashtable(obj_hashtable && source) noexcept = default;
obj_hashtable& operator=(const obj_hashtable & other) = delete;
obj_hashtable& operator=(obj_hashtable && other) noexcept = default;
};
template<typename Key, typename Value>
class obj_map {
public:
struct key_data {
Key * m_key = nullptr;
Value m_value;
key_data() {}
key_data(Key *key) : m_key(key) {}
key_data(Key *k, Value const &v) : m_key(k), m_value(v) {}
key_data(key_data &&kd) noexcept = default;
key_data(key_data const &kd) noexcept = default;
key_data &operator=(key_data const &kd) = default;
key_data &operator=(key_data &&kd) = default;
Key * m_key = nullptr;
Value m_value;
Value const & get_value() const { return m_value; }
Key & get_key () const { return *m_key; }
unsigned hash() const { return m_key->hash(); }
@ -94,7 +91,12 @@ public:
public:
obj_map(unsigned initial_capacity = DEFAULT_HASHTABLE_INITIAL_CAPACITY):
m_table(initial_capacity) {}
obj_map(const obj_map & source) = default;
obj_map(obj_map && source) noexcept = default;
obj_map& operator=(const obj_map & other) = delete;
obj_map& operator=(obj_map && other) noexcept = default;
typedef typename table::iterator iterator;
typedef typename table::data data;
typedef typename table::entry entry;
@ -141,16 +143,22 @@ public:
return m_table.insert_if_not_there2(key_data(k, v))->get_data().m_value;
}
Value& insert_if_not_there(Key * k, Value && v) {
obj_map_entry * e = nullptr;
m_table.insert_if_not_there_core({k, std::move(v)}, e);
return e->get_data().m_value;
}
bool insert_if_not_there_core(Key * k, Value const & v, obj_map_entry * & et) {
return m_table.insert_if_not_there_core({k, v}, et);
}
obj_map_entry * insert_if_not_there3(Key * k, Value const & v) {
return m_table.insert_if_not_there2(key_data(k, v));
return m_table.insert_if_not_there2({k, v});
}
obj_map_entry * find_core(Key * k) const {
return m_table.find_core(key_data(k));
return m_table.find_core({k});
}
bool find(Key * const k, Value & v) const {

View file

@ -19,10 +19,6 @@ Revision History:
#include "util/s_integer.h"
s_integer s_integer::m_zero(0);
s_integer s_integer::m_one(1);
s_integer s_integer::m_minus_one(-1);
s_integer::s_integer(const char * str) {
m_val = static_cast<int>(strtol(str, nullptr, 10));
}

View file

@ -22,9 +22,6 @@ Revision History:
class s_integer {
int m_val = 0;
static s_integer m_zero;
static s_integer m_one;
static s_integer m_minus_one;
public:
unsigned hash() const {
@ -39,10 +36,6 @@ public:
public:
s_integer() = default;
explicit s_integer(int n):m_val(n) {}
struct i64 {};
explicit s_integer(int64_t i, i64):m_val(static_cast<int>(i)) {}
struct ui64 {};
explicit s_integer(uint64_t i, ui64):m_val(static_cast<int>(i)) {}
explicit s_integer(const char * str);
explicit s_integer(const rational & r):m_val(static_cast<int>(r.get_int64())) {}
@ -58,12 +51,12 @@ public:
uint64_t get_uint64() const { return m_val; }
static bool is_unsigned() { return true; }
unsigned get_unsigned() const { return static_cast<unsigned>(m_val); }
s_integer const& get_s_integer() const { return *this; }
s_integer const& get_infinitesimal() const { return zero(); }
s_integer get_s_integer() const { return *this; }
s_integer get_infinitesimal() const { return s_integer(0); }
static bool is_rational() { return true; }
s_integer const& get_rational() const { return *this; }
friend inline s_integer numerator(const s_integer & r) { return r; }
friend inline s_integer denominator(const s_integer & r) { return one(); }
friend inline s_integer denominator(const s_integer & r) { return s_integer(1); }
s_integer & operator+=(const s_integer & r) { m_val += r.m_val; return *this; }
s_integer & operator-=(const s_integer & r) { m_val -= r.m_val; return *this; }
s_integer & operator*=(const s_integer & r) { m_val *= r.m_val; return *this; }
@ -103,9 +96,6 @@ public:
return result;
}
static const s_integer & zero() { return m_zero; }
static const s_integer & one() { return m_one; }
static const s_integer & minus_one() { return m_minus_one; }
// Perform: this += c * k
void addmul(const s_integer & c, const s_integer & k) { m_val += c.m_val * k.m_val; }
void submul(const s_integer & c, const s_integer & k) { m_val -= c.m_val * k.m_val; }
@ -137,5 +127,3 @@ inline s_integer abs(const s_integer & r) {
}
return result;
}