@@ -200,29 +200,19 @@ class DomainCompleter
200200 populateDomains : (onComplete ) ->
201201 HistoryCache .use (history) =>
202202 @domains = {}
203- history .forEach (entry) =>
204- # We want each key in our domains hash to point to the most recent History entry for that domain.
205- domain = @ parseDomain (entry .url )
206- if domain
207- previousEntry = @domains [domain]
208- if previousEntry
209- previousEntry .entry = entry if previousEntry .lastVisitTime < entry .lastVisitTime
210- previousEntry .referenceCount += 1
211- else
212- @domains [domain] = { entry : entry, referenceCount : 1 }
203+ history .forEach (entry) => @ onPageVisited entry
213204 chrome .history .onVisited .addListener (@onPageVisited .bind (this ))
214205 chrome .history .onVisitRemoved .addListener (@onVisitRemoved .bind (this ))
215206 onComplete ()
216207
208+ # We want each key in our domains hash to point to the most recent History entry for that domain.
217209 onPageVisited : (newPage ) ->
218210 domain = @ parseDomain (newPage .url )
219211 if domain
220- previousEntry = @domains [domain]
221- if previousEntry
222- previousEntry .entry = newPage
223- previousEntry .referenceCount += 1
224- else
225- @domains [domain] = { entry : newPage, referenceCount : 1 }
212+ @domains [domain] ||= { entry : newPage, referenceCount : 0 }
213+ slot = @domains [domain]
214+ slot .entry = newPage if slot .entry .lastVisitTime < newPage .lastVisitTime
215+ slot .referenceCount += 1
226216
227217 onVisitRemoved : (toRemove ) ->
228218 if toRemove .allHistory
0 commit comments