unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* decode-coding-string and consing
@ 2003-02-10 16:47 Jesper Harder
  2003-02-10 20:01 ` Eli Zaretskii
       [not found] ` <mailman.1748.1044907500.21513.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 5+ messages in thread
From: Jesper Harder @ 2003-02-10 16:47 UTC (permalink / raw)


,----[ C-h f decode-coding-string RET ]
| decode-coding-string is a built-in function.
| (decode-coding-string STRING CODING-SYSTEM &optional NOCOPY)
| 
| Decode STRING which is encoded in CODING-SYSTEM, and return the result.
| Optional arg NOCOPY non-nil means it is OK to return STRING itself
| if the decoding operation is trivial.
`----

Under what conditions is the decoding operation "trivial"?

I was hoping that something like:

  (decode-coding-string "abc" 'us-ascii t) or
  (decode-coding-string "abc" 'latin-1 t)

wouldn't cons a new string; but unfortunaley it does.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: decode-coding-string and consing
  2003-02-10 16:47 Jesper Harder
@ 2003-02-10 20:01 ` Eli Zaretskii
       [not found] ` <mailman.1748.1044907500.21513.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2003-02-10 20:01 UTC (permalink / raw)


> Newsgroups: gnu.emacs.help
> From: Jesper Harder <harder@myrealbox.com>
> Date: Mon, 10 Feb 2003 17:47:53 +0100
> 
> ,----[ C-h f decode-coding-string RET ]
> | decode-coding-string is a built-in function.
> | (decode-coding-string STRING CODING-SYSTEM &optional NOCOPY)
> | 
> | Decode STRING which is encoded in CODING-SYSTEM, and return the result.
> | Optional arg NOCOPY non-nil means it is OK to return STRING itself
> | if the decoding operation is trivial.
> `----
> 
> Under what conditions is the decoding operation "trivial"?

If CODING-SYSTEM is nil or such that no encoding is necessary at all.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: decode-coding-string and consing
       [not found] ` <mailman.1748.1044907500.21513.help-gnu-emacs@gnu.org>
@ 2003-02-10 21:53   ` Jesper Harder
  2003-02-11  6:32     ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Jesper Harder @ 2003-02-10 21:53 UTC (permalink / raw)


"Eli Zaretskii" <eliz@is.elta.co.il> writes:

>> ,----[ C-h f decode-coding-string RET ]
>> | decode-coding-string is a built-in function.
>> | (decode-coding-string STRING CODING-SYSTEM &optional NOCOPY)
>> | 
>> | Decode STRING which is encoded in CODING-SYSTEM, and return the result.
>> | Optional arg NOCOPY non-nil means it is OK to return STRING itself
>> | if the decoding operation is trivial.
>> `----
>> 
>> Under what conditions is the decoding operation "trivial"?
>
> If CODING-SYSTEM is nil or such that no encoding is necessary at all.

But I don't understand why any encoding is needed at all in:

    (decode-coding-string "abc" 'us-ascii t)

The input string and the output string are identical.  Why is it
necessary to cons a new string here?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: decode-coding-string and consing
  2003-02-10 21:53   ` Jesper Harder
@ 2003-02-11  6:32     ` Eli Zaretskii
  0 siblings, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2003-02-11  6:32 UTC (permalink / raw)



On Mon, 10 Feb 2003, Jesper Harder wrote:

> >> Under what conditions is the decoding operation "trivial"?
> >
> > If CODING-SYSTEM is nil or such that no encoding is necessary at all.
> 
> But I don't understand why any encoding is needed at all in:
> 
>     (decode-coding-string "abc" 'us-ascii t)

Why did you use us-ascii at all here?  It's not really a coding system.
Why not nil or raw-text?

Anyway, is there some real problem behind this discussion?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: decode-coding-string and consing
       [not found] <mailman.1774.1044945196.21513.help-gnu-emacs@gnu.org>
@ 2003-02-11 17:26 ` Jesper Harder
  0 siblings, 0 replies; 5+ messages in thread
From: Jesper Harder @ 2003-02-11 17:26 UTC (permalink / raw)


Eli Zaretskii <eliz@is.elta.co.il> writes:

> On Mon, 10 Feb 2003, Jesper Harder wrote:
>
>> > If CODING-SYSTEM is nil or such that no encoding is necessary at
>> > all.
>> 
>> But I don't understand why any encoding is needed at all in:
>> 
>>     (decode-coding-string "abc" 'us-ascii t)
>
> Why did you use us-ascii at all here?

It's just as an example where it's obvious that no encoding is needed.
What I'm really interested in is:

     (decode-coding-string "abc" 'latin-1 t)

i.e. decoding a pure ASCII string as latin-1 (or another strict superset
of ASCII).

This pseudo-code for what I'd like to do efficiently:

,----
| (defun my-decode-coding-string (string coding-system nocopy)
|   (if (and nocopy
| 	     (STRING has no 8bit chars)
| 	     (CODING-SYSTEM is a superset of ascii))
|       string
|     (decode-coding-string string coding-system nocopy)))
`----

> Anyway, is there some real problem behind this discussion?

Yes.  Gnus conses excessively.  

If `decode-coding-string' was a bit more clever about not consing a
string when it's not strictly necessary, we could cons ~ 2*N less
strings when constructing a summary buffer (N = number of articles).

It's also an issue when constructing a server buffer, where N is usually
large -- i.e. ~ 50.000-100.000 unnecessary strings are consed.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-02-11 17:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1774.1044945196.21513.help-gnu-emacs@gnu.org>
2003-02-11 17:26 ` decode-coding-string and consing Jesper Harder
2003-02-10 16:47 Jesper Harder
2003-02-10 20:01 ` Eli Zaretskii
     [not found] ` <mailman.1748.1044907500.21513.help-gnu-emacs@gnu.org>
2003-02-10 21:53   ` Jesper Harder
2003-02-11  6:32     ` Eli Zaretskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).