Skip to content

Commit a259a8c

Browse files
authored
Merge pull request #41 from radarroark/master
Improve efficiency of patch
2 parents 83e3632 + 046442e commit a259a8c

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/editscript/patch.cljc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
;;
1010

1111
(ns ^:no-doc editscript.patch
12-
(:require [clojure.set :as set]
13-
[editscript.edit :as e]
12+
(:require [editscript.edit :as e]
1413
[editscript.util.common :as c]
1514
[clojure.string :as s]))
1615

@@ -31,7 +30,7 @@
3130
;;if p is ##NaN, then p cannot be found in x, for (= ##NaN ##NaN) is false!
3231
:map (dissoc x p)
3332
:vec (into (subvec x 0 p) (subvec x (inc ^long p)))
34-
:set (set/difference x #{p})
33+
:set (disj x p)
3534
:lst (->> (split-at p x)
3635
(#(concat (nth % 0) (next (nth % 1))))
3736
(apply list))))
@@ -40,7 +39,9 @@
4039
[x p v]
4140
(case (e/get-type x)
4241
:map (assoc x p v)
43-
:vec (into (conj (subvec x 0 p) v) (subvec x p))
42+
:vec (if (= p (count x))
43+
(conj x v)
44+
(into (conj (subvec x 0 p) v) (subvec x p)))
4445
:set (conj x v)
4546
:lst (->> (split-at p x)
4647
(#(concat (nth % 0) (conj (nth % 1) v)))
@@ -74,8 +75,8 @@
7475
[x p v]
7576
(case (e/get-type x)
7677
:map (assoc x p v)
77-
:vec (into (conj (subvec x 0 p) v) (subvec x (inc ^long p)))
78-
:set (-> x (set/difference #{p}) (conj v))
78+
:vec (assoc x p v)
79+
:set (-> x (disj p) (conj v))
7980
:lst (->> (split-at p x)
8081
(#(concat (nth % 0) (conj (rest (nth % 1)) v)))
8182
(apply list))))

0 commit comments

Comments
 (0)