[Urwid] Optimize urwid
Victor Stinner
victor.stinner at haypocalc.com
Fri Dec 29 10:23:54 EST 2006
Le Vendredi 29 Décembre 2006 15:43, Ian Ward a écrit :
> Victor Stinner wrote:
> > ====================== 8< ========================================
> > def _get_width( o ):
> > global widths
> > if o == 0xe or o == 0xf:
> > return 0
> > for num, wid in widths:
> > if o <= num:
> > return wid
> > return 1
> > def get_width( o ):
> > """Return the screen column width for unicode ordinal o."""
> > global _get_width_cache
> > if o not in _get_width_cache:
> > _get_width_cache[o] = _get_width(o)
> > return _get_width_cache[o]
> > ====================== 8< ========================================
> >
> > In my program, the cache has 71 entries. That's small ;-)
>
> That's madness! :-) Instead of storing the entire string (...)
o is an Unicode character (an integer), not a string!
> > Manipulate UTF-8 is complex. In general, it would be a better idea to
> > only store Unicode string, and convert to UTF-8 when text is written in
> > the terminal.
>
> Yes, that is the recommended approach when writing Python programs. I
> chose to be more accepting, since I'm writing a library for other
> programmers to use.
I have to check if my program speak UTF-8 to urwid or Unicode... I think that
I convert strings just before sending them to urwid. So that's stupid :)
> > And also:
> > http://excess.org/urwid/ticket/2
> > C code for performance critical sections
>
> I believe that Rebecca Breu has done some work on this. I hope she
> finds some time to post her work, I'd like to try it out.
Cool, I may help on this code.
Haypo
--
Victor Stinner aka haypo
http://hachoir.org/
More information about the Urwid
mailing list