emacs-devel
[Top][All Lists]
Advanced

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

Re: struct.el -- a package to encode/decode binary data


From: Eli Zaretskii
Subject: Re: struct.el -- a package to encode/decode binary data
Date: Thu, 21 Mar 2002 16:56:31 +0200 (IST)

On 21 Mar 2002, Kim F. Storm wrote:

> > > Is there some specific reason not to use unibyte strings here?
> > 
> > They are simply not needed here (AFAICS). 
> 
> On the surface, it looks "obvious" to use unibyte strings for
> data which is known to be - and processed as - byte-oriented
> data.

That's the C programmer in you trying to get free ;-)

Seriously, though: I think we should stop thinking about unibyte vs 
multibyte strings, and instead think about them as, well, just strings.
The uni- vs multi-byteness is an implementation detail that should not 
bother a Lisp programmer.  (That it sometimes does is a sign of bugs 
that need to be fixed, IMHO.)

Emacs 21 is perfectly capable of holding binary data in a multibyte 
buffer, so there's no need to do this on the Lisp level.  If Emacs 
decides that a buffer needs to be switched to unibyte mode, it will do
so automatically.

> >                                            IMO, unibyte strings
> > should not be used unless absolutely necessary, ideally never.
> 
> Am I right in assuming that aref, aset, and substring are potentially
> much slower on a multibyte string than on a unibyte string?

If the string holds non-ASCII text, yes.  But not in your case, where the 
``string'' holds binary data, I think.

Also, I think the slow-down should be noticeable when you need to walk 
many characters, like when you invoke substring with a large argument.  
In your case, you take a small number of characters and then run some 
Lisp on them (e.g. to convert them into a number), so I think the 
slow-down will be negligible.  But that's speculation: I didn't really do 
any measurements, so some complication might be evading me.



reply via email to

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