help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to count the number of occurrences of a character in a string?


From: Eli Zaretskii
Subject: Re: How to count the number of occurrences of a character in a string?
Date: Wed, 14 Oct 2015 20:06:41 +0300

> From: Oleh Krehel <ohwoeowho@gmail.com>
> Date: Wed, 14 Oct 2015 12:04:52 +0200
> 
> (defun my-count (char str)
>   (let ((count 0)
>         (end (length str))
>         (i 0)
>         x)
>     (while (< i end)
>       (setq x (aref str i))
>       (if (eq char x)
>           (setq count (1+ count)))
>       (setq i (1+ i)))
>     count))
> 
> While `my-count' is twice as fast, I'd still recommend to use
> `cl-count', unless the code is very performance-critical.

Why?  There's nothing wrong with aref.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]