git-gui: Optimize encoding name resolution using a lookup table.
Encoding menu construction does almost a hundred of encoding resolutions, which with the old implementation led to a small but noticeable delay. Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com> Tested-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
parent
3fe0162362
commit
a1c3feb7fa
@ -286,39 +286,63 @@ set encoding_groups {
|
|||||||
{"Symbol" Symbol Dingbats MacDingbats MacCentEuro}}
|
{"Symbol" Symbol Dingbats MacDingbats MacCentEuro}}
|
||||||
}
|
}
|
||||||
|
|
||||||
proc tcl_encoding {enc} {
|
proc build_encoding_table {} {
|
||||||
global encoding_aliases
|
global encoding_aliases encoding_lookup_table
|
||||||
set names [encoding names]
|
|
||||||
set lcnames [string tolower $names]
|
# Prepare the lookup list; cannot use lsort -nocase because
|
||||||
set enc [string tolower $enc]
|
# of compatibility issues with older Tcl (e.g. in msysgit)
|
||||||
set i [lsearch -exact $lcnames $enc]
|
set names [list]
|
||||||
if {$i < 0} {
|
foreach item [encoding names] {
|
||||||
# look for "isonnn" instead of "iso-nnn" or "iso_nnn"
|
lappend names [list [string tolower $item] $item]
|
||||||
if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
|
|
||||||
set i [lsearch -exact $lcnames $encx]
|
|
||||||
}
|
}
|
||||||
}
|
set names [lsort -ascii -index 0 $names]
|
||||||
if {$i < 0} {
|
# neither can we use lsearch -index
|
||||||
foreach l $encoding_aliases {
|
set lnames [list]
|
||||||
set ll [string tolower $l]
|
foreach item $names {
|
||||||
if {[lsearch -exact $ll $enc] < 0} continue
|
lappend lnames [lindex $item 0]
|
||||||
# look through the aliases for one that tcl knows about
|
}
|
||||||
foreach e $ll {
|
|
||||||
set i [lsearch -exact $lcnames $e]
|
foreach grp $encoding_aliases {
|
||||||
if {$i < 0} {
|
set target {}
|
||||||
if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} {
|
foreach item $grp {
|
||||||
set i [lsearch -exact $lcnames $ex]
|
set i [lsearch -sorted -ascii $lnames \
|
||||||
}
|
[string tolower $item]]
|
||||||
|
if {$i >= 0} {
|
||||||
|
set target [lindex $names $i 1]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if {$target eq {}} continue
|
||||||
|
foreach item $grp {
|
||||||
|
set encoding_lookup_table([string tolower $item]) $target
|
||||||
}
|
}
|
||||||
if {$i >= 0} break
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if {$i >= 0} {
|
foreach item $names {
|
||||||
return [lindex $names $i]
|
set encoding_lookup_table([lindex $item 0]) [lindex $item 1]
|
||||||
}
|
}
|
||||||
return {}
|
}
|
||||||
|
|
||||||
|
proc tcl_encoding {enc} {
|
||||||
|
global encoding_lookup_table
|
||||||
|
if {$enc eq {}} {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
if {![info exists encoding_lookup_table]} {
|
||||||
|
build_encoding_table
|
||||||
|
}
|
||||||
|
set enc [string tolower $enc]
|
||||||
|
if {![info exists encoding_lookup_table($enc)]} {
|
||||||
|
# look for "isonnn" instead of "iso-nnn" or "iso_nnn"
|
||||||
|
if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
|
||||||
|
set enc $encx
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if {[info exists encoding_lookup_table($enc)]} {
|
||||||
|
return $encoding_lookup_table($enc)
|
||||||
|
} else {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
proc force_path_encoding {path enc} {
|
proc force_path_encoding {path enc} {
|
||||||
|
Loading…
Reference in New Issue
Block a user