Skip to content

Commit

Permalink
make weak_key_hash_table_pairs into a member function
Browse files Browse the repository at this point in the history
  • Loading branch information
Bike committed Dec 7, 2024
1 parent 4199135 commit fd84053
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
3 changes: 1 addition & 2 deletions include/clasp/gctools/gcweak.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,9 @@ class WeakKeyHashTable {
void maphashFn(core::T_sp fn);
bool remhash(core::T_sp tkey);
void clrhash();
core::Vector_sp pairs() const;
};

core::Vector_sp weak_key_hash_table_pairs(const gctools::WeakKeyHashTable& ht);

// ======================================================================
// ----------------------------------------------------------------------

Expand Down
3 changes: 1 addition & 2 deletions src/core/hashTable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ CL_DEFUN Vector_sp core__hash_table_pairs(HashTableBase_sp hash_table_base) {
return keyvalues;
} else if (gc::IsA<WeakKeyHashTable_sp>(hash_table_base)) {
WeakKeyHashTable_sp hash_table = gc::As_unsafe<WeakKeyHashTable_sp>(hash_table_base);
gctools::WeakKeyHashTable& wkht = hash_table->_HashTable;
return gctools::weak_key_hash_table_pairs(wkht);
return hash_table->_HashTable.pairs();
}
TYPE_ERROR(hash_table_base, Cons_O::createList(cl::_sym_or, cl::_sym_HashTable_O, core::_sym_WeakKeyHashTable_O));
}
Expand Down
13 changes: 6 additions & 7 deletions src/gctools/gcweak.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,14 @@ void WeakKeyHashTable::clrhash() {
});
};

DOCGROUP(clasp);
CL_DEFUN core::Vector_sp weak_key_hash_table_pairs(const gctools::WeakKeyHashTable& ht) {
size_t len = (*ht._Keys).length();
core::Vector_sp WeakKeyHashTable::pairs() const {
size_t len = (*_Keys).length();
core::ComplexVector_T_sp keyvalues = core::ComplexVector_T_O::make(len * 2, nil<core::T_O>(), core::make_fixnum(0));
HT_READ_LOCK(&ht);
HT_READ_LOCK(this);
for (size_t i(0); i < len; ++i) {
if ((*ht._Keys)[i].raw_() && !(*ht._Keys)[i].unboundp() && !(*ht._Keys)[i].deletedp()) {
keyvalues->vectorPushExtend((*ht._Keys)[i], 16);
keyvalues->vectorPushExtend((*ht._Values)[i], 16);
if ((*_Keys)[i].raw_() && !(*_Keys)[i].unboundp() && !(*_Keys)[i].deletedp()) {
keyvalues->vectorPushExtend((*_Keys)[i], 16);
keyvalues->vectorPushExtend((*_Values)[i], 16);
}
}
return keyvalues;
Expand Down

0 comments on commit fd84053

Please sign in to comment.