This is an automated email from the ASF dual-hosted git repository.

nickva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb-jiffy.git

commit 09a75e966d041b0b57cc3f48d41969ad28e62101
Author: Nick Vatamaniuc <[email protected]>
AuthorDate: Thu Apr 2 19:35:33 2026 -0400

    Optimize dedupe_keys option
    
    Switch sets in objects.cc (used for deduping keys) from an `set` to
    `unordered_set`. Unordered sets have O(1) lookups and regular sets have
    O(logN).
    
    This option mostly useful for projects like Apache CouchDB which rely on the
    proplist represention and use the `dedupe_keys`.
    
    Since we're trying to be backwards comptable as much as possible let's add a
    macro check and use a `set` if `unordered` set is not available.
---
 c_src/objects.cc | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/c_src/objects.cc b/c_src/objects.cc
index 2a35b25..121e062 100644
--- a/c_src/objects.cc
+++ b/c_src/objects.cc
@@ -1,9 +1,16 @@
 // This file is part of Jiffy released under the MIT license.
 // See the LICENSE file for more information.
 
-#include <set>
 #include <string>
 
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+  #include <unordered_set>
+  typedef std::unordered_set<std::string> string_set;
+#else
+  #include <set>
+  typedef std::set<std::string> string_set;
+#endif
+
 #include <assert.h>
 
 #include "erl_nif.h"
@@ -21,7 +28,7 @@ make_object(ErlNifEnv* env, ERL_NIF_TERM pairs, ERL_NIF_TERM* 
out,
     ERL_NIF_TERM key;
     ERL_NIF_TERM val;
 
-    std::set<std::string> seen;
+    string_set seen;
 
     ERL_NIF_TERM old_val;
 

Reply via email to