diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2023-01-16 11:03:48 +0100 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2023-01-16 11:14:24 +0100 |
| commit | cd9e563ea036595b3def00f83d2aa9d4a12b7c06 (patch) | |
| tree | c4a9773bfbd12130313f3de64930483248e5b1f5 /compat-28.el | |
| parent | 45ae45a6d17ba389db32f38cc5dae33ee9a3d24b (diff) | |
Drop JSON support for now (libjansson)
I have not taken this decision lightly. There are currently no
consumers of the backported JSON api, which allows us to take this
measure. The problem is that backporting the libjansson API on top of
json.el is non-trivial and led to numerous problems:
1. There is a significant mismatch between the libjansson API and the
json.el API.
2. The libjansson API did not support RFC 8259 when it was introduced
in 27 This was corrected in 28, which requires Compat to provide two
compatibility versions for the json functions.
3. The `json-serialize' compatibility function was very inefficient,
since it has to walk and copy the entire object tree in order to
repair certain objects for the consumption by `json-encode'. This adds
slowness on top of the already slow json.el implementation.
4. `json-parse-buffer' (RFC 8259) modifies the buffer in order to
support toplevel object parsing and relies on undo to restore the
buffer state. This will not work for read-only buffers and for buffers
with disable undo and will have other undesired side effects.
5. The performance of libjansson and json.el are too different. It
will be unexpected if a backported API is suddenly much slower as
expected. This leads to performance bugs downstream.
For now the JSON support lives in the json branch. We can reinstate it
slowly and on-demand if necessary. However experience with the
`string-pixel-width' function showed that we have to be careful when
backports are much slower than the original function due to
performance bugs.
Diffstat (limited to 'compat-28.el')
| -rw-r--r-- | compat-28.el | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/compat-28.el b/compat-28.el index 8219633..6aef33d 100644 --- a/compat-28.el +++ b/compat-28.el @@ -150,59 +150,6 @@ If COUNT is non-nil and a natural number, the function will (setf (nthcdr count files) nil)) files)) -;;;; Defined in json.c - -;; TODO Check interaction with conditionally defined json functions -(compat-defun json-serialize (object &rest args) ;; <UNTESTED> - "Handle top-level JSON values (RFC 8259)." - :explicit t - :cond (= 27 emacs-major-version) - (if (or (listp object) (vectorp object)) - (apply #'json-serialize object args) - (substring (json-serialize (list object)) 1 -1))) - -;; TODO Check interaction with conditionally defined json functions -(compat-defun json-insert (object &rest args) ;; <UNTESTED> - "Handle top-level JSON values (RFC 8259)." - :explicit t - :cond (= 27 emacs-major-version) - (if (or (listp object) (vectorp object)) - (apply #'json-insert object args) - (insert (apply #'compat--json-serialize object args)))) - -;; TODO Check interaction with conditionally defined json functions -(compat-defun json-parse-string (string &rest args) ;; <UNTESTED> - "Handle top-level JSON values (RFC 8259)." - :explicit t - :cond (= 27 emacs-major-version) - (if (string-match-p "\\`[[:space:]]*[[{]" string) - (apply #'json-parse-string string args) - ;; Wrap the string in an array, and extract the value back using - ;; `elt', to ensure that no matter what the value of `:array-type' - ;; is we can access the first element. - (elt (apply #'json-parse-string (concat "[" string "]") args) 0))) - -;; TODO Check interaction with conditionally defined json functions -(compat-defun json-parse-buffer (&rest args) ;; <UNTESTED> - "Handle top-level JSON values (RFC 8259)." - :explicit t - :cond (= 27 emacs-major-version) - (if (looking-at-p "[[:space:]]*[[{]") - (apply #'json-parse-buffer args) - (catch 'escape - (atomic-change-group - (with-syntax-table - (let ((st (make-syntax-table))) - (modify-syntax-entry ?\" "\"" st) - (modify-syntax-entry ?. "_" st) - st) - (let ((inhibit-read-only t)) - (save-excursion - (insert "[") - (forward-sexp 1) - (insert "]")))) - (throw 'escape (elt (apply #'json-parse-buffer args) 0)))))) - ;;;; xfaces.c (compat-defun color-values-from-color-spec (spec) ;; <compat-tests:color-values-from-color-spec> |
