Skip to content

Commit

Permalink
Requesting for dictionary keys also respects insertion order, closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
reduz committed Jul 23, 2017
1 parent 9e48360 commit cf286ed
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions core/dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ uint32_t Dictionary::hash() const {

Array Dictionary::keys() const {

#if 0
Array karr;
karr.resize(size());
const Variant *K = NULL;
Expand All @@ -208,6 +209,26 @@ Array Dictionary::keys() const {
karr[idx++] = (*K);
}
return karr;
#else

Array varr;
varr.resize(size());
if (_p->variant_map.empty())
return varr;

int count = _p->variant_map.size();
const HashMap<Variant, DictionaryPrivate::Data, _DictionaryVariantHash>::Pair **pairs = (const HashMap<Variant, DictionaryPrivate::Data, _DictionaryVariantHash>::Pair **)alloca(count * sizeof(HashMap<Variant, DictionaryPrivate::Data, _DictionaryVariantHash>::Pair *));
_p->variant_map.get_key_value_ptr_array(pairs);

SortArray<const HashMap<Variant, DictionaryPrivate::Data, _DictionaryVariantHash>::Pair *, DictionaryPrivateSort> sort;
sort.sort(pairs, count);

for (int i = 0; i < count; i++) {
varr[i] = pairs[i]->key;
}

return varr;
#endif
}

Array Dictionary::values() const {
Expand Down

0 comments on commit cf286ed

Please sign in to comment.