Optimized sorter initialization

master
Michael Dvorkin 11 years ago
parent e9d2dfacbe
commit 69fa0d1819
  1. 8
      layout.go

@ -25,6 +25,7 @@ type Column struct {
type Layout struct { type Layout struct {
columns []Column columns []Column
sorter *Sorter
regex *regexp.Regexp regex *regexp.Regexp
market_template *template.Template market_template *template.Template
quotes_template *template.Template quotes_template *template.Template
@ -134,10 +135,13 @@ func (self *Layout) prettify(quotes *Quotes) []Stock {
} }
profile := quotes.profile profile := quotes.profile
new(Sorter).Initialize(profile).SortByCurrentColumn(pretty) if self.sorter == nil { // Initialize sorter on first invocation.
self.sorter = new(Sorter).Initialize(profile)
}
self.sorter.SortByCurrentColumn(pretty)
// //
// Group stocks by advancing/declining unless sorted by Chanage or Change% // Group stocks by advancing/declining unless sorted by Chanage or Change%
// in which case the grouping is done already. // in which case the grouping has been done already.
// //
if profile.Grouped && (profile.SortColumn < 2 || profile.SortColumn > 3) { if profile.Grouped && (profile.SortColumn < 2 || profile.SortColumn > 3) {
pretty = group(pretty) pretty = group(pretty)

Loading…
Cancel
Save