From 69fa0d18197340c2879a0e125809e077dde19e1a Mon Sep 17 00:00:00 2001 From: Michael Dvorkin Date: Fri, 9 Aug 2013 22:08:14 -0700 Subject: [PATCH] Optimized sorter initialization --- layout.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/layout.go b/layout.go index a0edf6e..7fb6da0 100644 --- a/layout.go +++ b/layout.go @@ -25,6 +25,7 @@ type Column struct { type Layout struct { columns []Column + sorter *Sorter regex *regexp.Regexp market_template *template.Template quotes_template *template.Template @@ -134,10 +135,13 @@ func (self *Layout) prettify(quotes *Quotes) []Stock { } 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% - // 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) { pretty = group(pretty)