slow fileutil::foreachLine

Liste des GroupesRevenir à cl tcl 
Sujet : slow fileutil::foreachLine
De : mark (at) *nospam* qtrac.eu (Mark Summerfield)
Groupes : comp.lang.tcl
Date : 17. Jun 2024, 08:02:59
Autres entêtes
Message-ID : <nY-dnZ1fQb8-QvL7nZ2dnZfqn_GdnZ2d@brightview.co.uk>
User-Agent : Pan/0.154 (Izium; 517acf4)
I have this function:

proc ws::get_words {wordfile} {
    set in [open $wordfile r]
    try {
        while {[gets $in line] >= 0} {
            if {[regexp {^[a-z]+$} $line matched]} {
                lappend ::ws::Words [string tolower $matched]
            }
        }
    } finally {
        close $in
    }
}

It reads about 100_000 lines and ends up keeping about 65_000 of them
(from /usr/share/dict/words)

I tried replacing it with:

proc ws::get_words {wordfile} {
    ::fileutil::foreachLine line $wordfile {
        if {[regexp {^[a-z]+$} $line matched]} {
            lappend ::ws::Words [string tolower $matched]
        }
    }
}

The first version loads "instantly"; but the second version (with
foreachLine) takes seconds.

I'm using Tcl/Tk 9.0b2

Date Sujet#  Auteur
17 Jun 24 * slow fileutil::foreachLine2Mark Summerfield
17 Jun 24 `- Re: slow fileutil::foreachLine1Rich

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal