Ineffient code in tramp.el

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Ineffient code in tramp.el

Kim Storm

Tramp has this function:

(defun tramp-match-string-list (&optional string)
  "Returns list of all match strings.
That is, (list (match-string 0) (match-string 1) ...), according to the
number of matches."
  (let* ((nmatches (/ (length (match-data)) 2))
         (i (- nmatches 1))
         (res nil))
    (while (>= i 0)
      (setq res (cons (match-string i string) res))
      (setq i (- i 1)))
    res))


It is used in function tramp-wait-for-regexp only, and all uses of
that function only tests whether the return value is nil or non-nil.

So the above code seems like vast overkill to me :-)

--
Kim F. Storm <[hidden email]> http://www.cua.dk



_______________________________________________
Emacs-devel mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-devel
Reply | Threaded
Open this post in threaded view
|

Re: Ineffient code in tramp.el

David Kastrup
[hidden email] (Kim F. Storm) writes:

> Tramp has this function:
>
> (defun tramp-match-string-list (&optional string)
>   "Returns list of all match strings.
> That is, (list (match-string 0) (match-string 1) ...), according to the
> number of matches."
>   (let* ((nmatches (/ (length (match-data)) 2))
>          (i (- nmatches 1))
>          (res nil))
>     (while (>= i 0)
>       (setq res (cons (match-string i string) res))
>       (setq i (- i 1)))
>     res))
>
>
> It is used in function tramp-wait-for-regexp only, and all uses of
> that function only tests whether the return value is nil or non-nil.
>
> So the above code seems like vast overkill to me :-)

In addition, (/ (length (match-data)) 2) creates a whole slew of
markers that slow down editing operations until the next garbage
collection.  You should rather use
(/ (length (match-data t)) 2)
if you really must.

--
David Kastrup, Kriemhildstr. 15, 44793 Bochum


_______________________________________________
Emacs-devel mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-devel