From: Ivan Shmakov <ivan@siamics.net>
To: 20154@debbugs.gnu.org
Subject: bug#20154: 25.0.50; json-encode-string is too slow for large strings
Date: Sat, 21 Mar 2015 22:20:51 +0000 [thread overview]
Message-ID: <87a8z6vvp8.fsf@violet.siamics.net> (raw)
In-Reply-To: <550DDE25.1090000@yandex.ru> (Dmitry Gutov's message of "Sat, 21 Mar 2015 23:09:57 +0200")
>>>>> Dmitry Gutov <dgutov@yandex.ru> writes:
[…]
> Here's the updated definition (by the way, `json-special-chars' is
> still needed, to convert ?\n to ?n, and so on, and the performance
> hit is negligible).
Perhaps a plain vector may fit there?
> (defun json-encode-string-1 (string)
> "Return a JSON representation of STRING."
> (with-temp-buffer
> (insert string)
> (goto-char (point-min))
> ;; Skip over ASCIIish printable characters.
> (while (re-search-forward "\\([\"\\/\b\f\n\r\t]\\)\\|[^ -~]" nil t)
> (let ((c (char-before)))
> (delete-region (1- (point)) (point))
> (if (match-beginning 1)
> ;; Special JSON character (\n, \r, etc.).
> (insert "\\" (car (rassoc c json-special-chars)))
> ;; Fallback: UCS code point in \uNNNN form.
> (insert (format "\\u%04x" c)))))
> (concat "\"" (buffer-string) "\"")))
FWIW, using replace-match in the loop seem to speed up the
routine by another few percents.
(while (re-search-forward "\\([\"\\/\b\f\n\r\t]\\)\\|[^ -~]" nil t)
(let ((c (char-before)))
(replace-match
(if (match-beginning 1)
;; Special JSON character (\n, \r, etc.).
(string ?\\ (car (rassq c json-special-chars)))
;; Fallback: UCS code point in \uNNNN form.
(format "\\u%04x" c))
t t)))
[…]
--
FSF associate member #7257 http://boycottsystemd.org/ … 3013 B6A0 230E 334A
next prev parent reply other threads:[~2015-03-21 22:20 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-20 14:26 bug#20154: 25.0.50; json-encode-string is too slow for large strings Dmitry Gutov
2015-03-20 14:34 ` Eli Zaretskii
2015-03-20 14:43 ` Dmitry Gutov
2015-03-20 15:03 ` Eli Zaretskii
2015-03-20 15:20 ` Dmitry Gutov
2015-03-20 16:02 ` Eli Zaretskii
2015-03-20 16:21 ` Dmitry Gutov
2015-03-20 16:44 ` Eli Zaretskii
2015-03-20 16:52 ` Dmitry Gutov
2015-03-20 17:44 ` Eli Zaretskii
2015-03-20 18:42 ` Dmitry Gutov
2015-03-20 21:14 ` Eli Zaretskii
2015-03-20 22:02 ` Dmitry Gutov
2015-03-21 7:58 ` Eli Zaretskii
2015-03-21 8:12 ` Eli Zaretskii
2015-03-21 20:00 ` Dmitry Gutov
2015-03-21 20:25 ` Eli Zaretskii
2015-03-21 21:26 ` Dmitry Gutov
2015-03-22 17:31 ` Eli Zaretskii
2015-03-22 18:13 ` Dmitry Gutov
2015-03-22 18:26 ` Dmitry Gutov
2015-03-22 18:32 ` Eli Zaretskii
2015-03-22 19:03 ` Dmitry Gutov
2015-03-21 21:05 ` Drew Adams
2015-03-21 21:32 ` Dmitry Gutov
2015-04-20 22:20 ` Ted Zlatanov
2015-04-20 22:41 ` Dmitry Gutov
2015-04-20 23:11 ` Ted Zlatanov
2015-03-20 22:26 ` Dmitry Gutov
2015-03-21 8:07 ` Eli Zaretskii
2015-03-21 21:09 ` Dmitry Gutov
2015-03-21 22:20 ` Ivan Shmakov [this message]
2015-03-21 23:36 ` Dmitry Gutov
2015-03-22 14:52 ` Dmitry Gutov
2015-03-22 16:15 ` Ivan Shmakov
2015-03-22 16:47 ` Dmitry Gutov
2015-03-22 17:43 ` Eli Zaretskii
2015-03-22 19:15 ` Ivan Shmakov
2015-03-22 16:51 ` Eli Zaretskii
2015-03-22 20:07 ` mailing lists and Cc: Ivan Shmakov
2015-03-22 18:22 ` bug#20154: 25.0.50; json-encode-string is too slow for large strings Glenn Morris
2015-03-22 19:45 ` mailing lists and Cc: Ivan Shmakov
2015-03-22 16:50 ` bug#20154: 25.0.50; json-encode-string is too slow for large strings Eli Zaretskii
2015-03-22 17:10 ` Dmitry Gutov
2015-03-22 22:57 ` Dmitry Gutov
2015-03-23 15:37 ` Eli Zaretskii
2015-04-07 13:31 ` Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a8z6vvp8.fsf@violet.siamics.net \
--to=ivan@siamics.net \
--cc=20154@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.