GNU bug report logs - #20154
25.0.50; json-encode-string is too slow for large strings

Previous Next

Package: emacs;

Reported by: Dmitry Gutov <dgutov <at> yandex.ru>

Date: Fri, 20 Mar 2015 14:27:01 UTC

Severity: normal

Found in version 25.0.50

Done: Dmitry Gutov <dgutov <at> yandex.ru>

Bug is archived. No further changes may be made.

Full log


Message #50 received at 20154 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: 20154 <at> debbugs.gnu.org
Subject: Re: bug#20154: 25.0.50;
 json-encode-string is too slow for large strings
Date: Sat, 21 Mar 2015 10:07:22 +0200
> Date: Sat, 21 Mar 2015 00:26:03 +0200
> From: Dmitry Gutov <dgutov <at> yandex.ru>
> CC: 20154 <at> debbugs.gnu.org
> 
> As per your comment, this seems to be the best we can do for long 
> strings, without diving into C:
> 
> (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)
>        (replace-match
>         (if (match-beginning 1)
>             ;; Special JSON character (\n, \r, etc.).
>             (format "\\%c" (char-after (match-beginning 0)))

Do you really need 'format' here?  Why not

    (concat "\\" (char-to-string (char-after (match-beginning 0))))

instead?

Or even simply insert these two parts at the match point, after
deleting the match.




This bug report was last modified 10 years and 38 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.