Skip to content

Commit

Permalink
Optimized val-at-datom
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed Jun 2, 2023
1 parent 0456554 commit 623ae9e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ TODO.txt
web/*.js
web/out
web/target-cljs
.rebl
.rebl
.shadow-cljs
7 changes: 0 additions & 7 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@
}
}

:nrepl {
:extra-deps {
nrepl/nrepl {:mvn/version "1.0.0"}
lambdaisland/deep-diff2 {:mvn/version "2.0.108"}
}
}

:datomic {
:extra-paths ["test_datomic"]
:extra-deps {
Expand Down
5 changes: 5 additions & 0 deletions script/repl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail
cd "`dirname $0`/.."

clj -A:test:bench -J--add-opens=java.base/java.io=ALL-UNNAMED -X clojure.core.server/start-server :name repl :port 5555 :accept clojure.core.server/repl :server-daemon false
28 changes: 20 additions & 8 deletions src/datascript/db.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,26 @@
;; keep it fast by duplicating for both keyword and string cases
;; instead of using sets or some other matching func
(defn- val-at-datom [^Datom d k not-found]
(case k
:e (.-e d) "e" (.-e d)
:a (.-a d) "a" (.-a d)
:v (.-v d) "v" (.-v d)
:tx (datom-tx d)
"tx" (datom-tx d)
:added (datom-added d)
"added" (datom-added d)
(cond
(keyword? k)
(case k
:e (.-e d)
:a (.-a d)
:v (.-v d)
:tx (datom-tx d)
:added (datom-added d)
not-found)

(string? k)
(case k
"e" (.-e d)
"a" (.-a d)
"v" (.-v d)
"tx" (datom-tx d)
"added" (datom-added d)
not-found)

:else
not-found))

(defn- nth-datom
Expand Down

0 comments on commit 623ae9e

Please sign in to comment.