-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a new linter:
:performance
Closes #416
- Loading branch information
Showing
12 changed files
with
240 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(ns testcases.performance.green.case) | ||
|
||
(defn foo [x] | ||
(case (long x) | ||
1 :one)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(ns testcases.performance.green.hash) | ||
|
||
(case 1 1 :long 922337203900225948N :big 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
(ns testcases.performance.green.recur | ||
"Like `testcases.performance.green.recur` but adds a `long`` call | ||
to address the recur warning." | ||
(:require | ||
[clojure.string :as string])) | ||
|
||
(def ^:const vlq-base-shift 5) | ||
(def ^:const vlq-base (bit-shift-left 1 vlq-base-shift)) | ||
(def ^:const vlq-base-mask (dec vlq-base)) | ||
(def ^:const vlq-continuation-bit vlq-base) | ||
|
||
(defn to-vlq-signed [v] | ||
(if (neg? v) | ||
(inc (bit-shift-left (- v) 1)) | ||
(+ (bit-shift-left v 1) 0))) | ||
|
||
(defn from-vlq-signed [v] | ||
(let [neg? (= (bit-and v 1) 1) | ||
shifted (bit-shift-right v 1)] | ||
(if neg? | ||
(- shifted) | ||
shifted))) | ||
|
||
(defn decode [^String s] | ||
(let [l (.length s)] | ||
(loop [i 0 result 0 shift 0] | ||
(when (>= i l) | ||
(throw (Error. "Expected more digits in base 64 VLQ value."))) | ||
(let [digit (rand-int 10)] | ||
(let [i (inc i) | ||
continuation? (pos? (bit-and digit vlq-continuation-bit)) | ||
digit (bit-and digit vlq-base-mask) | ||
result (+ result (bit-shift-left digit shift)) | ||
shift (long (+ shift vlq-base-shift))] | ||
(if continuation? | ||
(recur i result shift) | ||
(lazy-seq | ||
(cons (from-vlq-signed result) | ||
(let [s (.substring s i)] | ||
(when-not (string/blank? s) | ||
(decode s))))))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(ns testcases.performance.red.case) | ||
|
||
(defn foo [x] | ||
(case x | ||
1 :one)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(ns testcases.performance.red.hash) | ||
|
||
(case 1 1 :long 9223372039002259457N :big 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
(ns testcases.performance.red.recur | ||
(:require | ||
[clojure.string :as string])) | ||
|
||
(def ^:const vlq-base-shift 5) | ||
(def ^:const vlq-base (bit-shift-left 1 vlq-base-shift)) | ||
(def ^:const vlq-base-mask (dec vlq-base)) | ||
(def ^:const vlq-continuation-bit vlq-base) | ||
|
||
(defn to-vlq-signed [v] | ||
(if (neg? v) | ||
(inc (bit-shift-left (- v) 1)) | ||
(+ (bit-shift-left v 1) 0))) | ||
|
||
(defn from-vlq-signed [v] | ||
(let [neg? (= (bit-and v 1) 1) | ||
shifted (bit-shift-right v 1)] | ||
(if neg? | ||
(- shifted) | ||
shifted))) | ||
|
||
(defn decode [^String s] | ||
(let [l (.length s)] | ||
(loop [i 0 result 0 shift 0] | ||
(when (>= i l) | ||
(throw (Error. "Expected more digits in base 64 VLQ value."))) | ||
(let [digit (rand-int 10)] | ||
(let [i (inc i) | ||
continuation? (pos? (bit-and digit vlq-continuation-bit)) | ||
digit (bit-and digit vlq-base-mask) | ||
result (+ result (bit-shift-left digit shift)) | ||
shift (+ shift vlq-base-shift)] | ||
(if continuation? | ||
(recur i result shift) | ||
(lazy-seq | ||
(cons (from-vlq-signed result) | ||
(let [s (.substring s i)] | ||
(when-not (string/blank? s) | ||
(decode s))))))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
(ns eastwood.linters.performance | ||
(:require | ||
[clojure.string :as string])) | ||
|
||
(defn linter [{:keys [performance-warnings]} _] | ||
(->> performance-warnings | ||
(map (fn [{:keys [post uri line column kind]}] | ||
{:linter :performance | ||
:kind kind | ||
:uri-or-file-name uri | ||
:loc {:line line | ||
:column column | ||
:file uri} | ||
:msg (-> post | ||
(string/replace #"^ - " "") | ||
(string/replace #"^ " " "))})))) |
Oops, something went wrong.