diff options
| author | Steve Block <steveblock@google.com> | 2009-10-08 17:19:54 +0100 |
|---|---|---|
| committer | Steve Block <steveblock@google.com> | 2009-10-20 00:41:58 +0100 |
| commit | 231d4e3152a9c27a73b6ac7badbe6be673aa3ddf (patch) | |
| tree | a6c7e2d6cd7bfa7011cc39abbb436142d7a4a7c8 /WebKit/mac/History | |
| parent | e196732677050bd463301566a68a643b6d14b907 (diff) | |
| download | external_webkit-231d4e3152a9c27a73b6ac7badbe6be673aa3ddf.zip external_webkit-231d4e3152a9c27a73b6ac7badbe6be673aa3ddf.tar.gz external_webkit-231d4e3152a9c27a73b6ac7badbe6be673aa3ddf.tar.bz2 | |
Merge webkit.org at R49305 : Automatic merge by git.
Change-Id: I8968561bc1bfd72b8923b7118d3728579c6dbcc7
Diffstat (limited to 'WebKit/mac/History')
| -rw-r--r-- | WebKit/mac/History/WebHistory.mm | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/WebKit/mac/History/WebHistory.mm b/WebKit/mac/History/WebHistory.mm index e971aba..6304fd2 100644 --- a/WebKit/mac/History/WebHistory.mm +++ b/WebKit/mac/History/WebHistory.mm @@ -148,27 +148,42 @@ private: #pragma mark MODIFYING CONTENTS -static WebHistoryDateKey timeIntervalForBeginningOfDay(NSTimeInterval interval) +static void getDayBoundaries(NSTimeInterval interval, NSTimeInterval& beginningOfDay, NSTimeInterval& beginningOfNextDay) { CFTimeZoneRef timeZone = CFTimeZoneCopyDefault(); CFGregorianDate date = CFAbsoluteTimeGetGregorianDate(interval, timeZone); date.hour = 0; date.minute = 0; date.second = 0; - NSTimeInterval result = CFGregorianDateGetAbsoluteTime(date, timeZone); + beginningOfDay = CFGregorianDateGetAbsoluteTime(date, timeZone); + date.day += 1; + beginningOfNextDay = CFGregorianDateGetAbsoluteTime(date, timeZone); CFRelease(timeZone); +} - // Converting from double to int64_t is safe here as NSDate's useful range - // is -2**48 .. 2**47 which will safely fit in an int64_t. - return (WebHistoryDateKey)result; +static inline NSTimeInterval beginningOfDay(NSTimeInterval date) +{ + static NSTimeInterval cachedBeginningOfDay = NAN; + static NSTimeInterval cachedBeginningOfNextDay; + if (!(date >= cachedBeginningOfDay && date < cachedBeginningOfNextDay)) + getDayBoundaries(date, cachedBeginningOfDay, cachedBeginningOfNextDay); + return cachedBeginningOfDay; +} + +static inline WebHistoryDateKey dateKey(NSTimeInterval date) +{ + // Converting from double (NSTimeInterval) to int64_t (WebHistoryDateKey) is + // safe here because all sensible dates are in the range -2**48 .. 2**47 which + // safely fits in an int64_t. + return beginningOfDay(date); } // Returns whether the day is already in the list of days, // and fills in *key with the key used to access its location - (BOOL)findKey:(WebHistoryDateKey*)key forDay:(NSTimeInterval)date { - ASSERT_ARG(key, key != nil); - *key = timeIntervalForBeginningOfDay(date); + ASSERT_ARG(key, key); + *key = dateKey(date); return _entriesByDate->contains(*key); } |
