Tk Library Source Code

View Ticket
Login
Ticket UUID: 532774
Title: ncgi::nvlist very slow for large queries
Type: Bug Version: None
Submitter: davidjgrossman Created on: 2002-03-20 22:29:21
Subsystem: ncgi Assigned To: gwlester
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2006-07-03 03:48:30
Resolution: Accepted Closed By: mic42
    Closed on: 2006-07-02 20:48:30
Description:
Obtaining the results of form submissions where a 
field contains a large amount of data ( >5-10kb ) 
causes the CPU to max out for long periods of time 
(several minutes for 40kb on a reasonably fast PC).

The problem is caused by the regular expression:

regexp -- (.*)=(.*) $x dummy varname val

which doesn't seem to handle really large strings well.

My fix was to use the following:

set pos [string first "=" $x]
set len [string length $x]

if { $pos>=0 } {
    if { $pos == 0 } { # if the = is at the 
beginning ...
        if { $len>1 } { # ... and there is something 
to the right ...
            set varname anonymous
            set val [string range $x 1 [expr $len-1]]
        } else { # ... otherwise, all we have is an =
            set varname anonymous
            set val ""
        }
    } elseif { $pos==[expr $len-1] } { # if the = is 
at the end ...
        set varname [string range $x 0 [expr $pos-1]]
        set val ""
    } else {
        set varname [string range $x 0 [expr $pos-1]]
        set val [string range $x [expr $pos+1] [expr 
$len-1]]
    }
} else { # no = was found ...
    set varname anonymous
    set val $x
}

in place of:

if {![regexp -- (.*)=(.*) $x dummy varname val]} {
    set varname anonymous
    set val $x
}

in ncgi::nvlist in tcllib/ncgi. I know that the 
problem exists in tcllib version 1.1 and 1.2.