summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-07-23 12:23:18 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-07-23 12:24:03 -0300
commitcf286ed28765606fc6834e7fdbaf5550159454b4 (patch)
treeff45af5ad1bf122bcdfae976c2851a5bf7111a7b
parent9e483604a5b957275ababf1a03a5992cb7bbd9c7 (diff)
Requesting for dictionary keys also respects insertion order, closes #9161
-rw-r--r--core/dictionary.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/core/dictionary.cpp b/core/dictionary.cpp
index e6d549b83d..1fe45aff94 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<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 {