From cf286ed28765606fc6834e7fdbaf5550159454b4 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 23 Jul 2017 12:23:18 -0300 Subject: [PATCH] Requesting for dictionary keys also respects insertion order, closes #9161 --- core/dictionary.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/core/dictionary.cpp b/core/dictionary.cpp index e6d549b83dd..1fe45aff940 100644 --- a/core/dictionary.cpp +++ b/core/dictionary.cpp @@ -200,6 +200,7 @@ uint32_t Dictionary::hash() const { Array Dictionary::keys() const { +#if 0 Array karr; karr.resize(size()); const Variant *K = NULL; @@ -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::Pair **pairs = (const HashMap::Pair **)alloca(count * sizeof(HashMap::Pair *)); + _p->variant_map.get_key_value_ptr_array(pairs); + + SortArray::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 {