comparison layer/ScrollableMagRangeCache.cpp @ 1164:f2f43802718b 3.0-integration

More timings and cache hit counts
author Chris Cannam
date Thu, 10 Nov 2016 09:58:28 +0000
parents c53ed1a6fcbd
children a34a2a25907c
comparison
equal deleted inserted replaced
1163:ab169938832a 1164:f2f43802718b
12 COPYING included with this distribution for more information. 12 COPYING included with this distribution for more information.
13 */ 13 */
14 14
15 #include "ScrollableMagRangeCache.h" 15 #include "ScrollableMagRangeCache.h"
16 16
17 #include "base/HitCount.h"
18
17 #include <iostream> 19 #include <iostream>
18 using namespace std; 20 using namespace std;
19 21
20 //#define DEBUG_SCROLLABLE_MAG_RANGE_CACHE 1 22 //#define DEBUG_SCROLLABLE_MAG_RANGE_CACHE 1
21 23
22 void 24 void
23 ScrollableMagRangeCache::scrollTo(const LayerGeometryProvider *v, 25 ScrollableMagRangeCache::scrollTo(const LayerGeometryProvider *v,
24 sv_frame_t newStartFrame) 26 sv_frame_t newStartFrame)
25 { 27 {
28 static HitCount count("ScrollableMagRangeCache: scrolling");
29
26 int dx = (v->getXForFrame(m_startFrame) - 30 int dx = (v->getXForFrame(m_startFrame) -
27 v->getXForFrame(newStartFrame)); 31 v->getXForFrame(newStartFrame));
28 32
29 #ifdef DEBUG_SCROLLABLE_MAG_RANGE_CACHE 33 #ifdef DEBUG_SCROLLABLE_MAG_RANGE_CACHE
30 cerr << "ScrollableMagRangeCache::scrollTo: start frame " << m_startFrame 34 cerr << "ScrollableMagRangeCache::scrollTo: start frame " << m_startFrame
31 << " -> " << newStartFrame << ", dx = " << dx << endl; 35 << " -> " << newStartFrame << ", dx = " << dx << endl;
32 #endif 36 #endif
33 37
34 if (m_startFrame == newStartFrame) { 38 if (m_startFrame == newStartFrame) {
35 // haven't moved 39 // haven't moved
40 count.hit();
36 return; 41 return;
37 } 42 }
38 43
39 m_startFrame = newStartFrame; 44 m_startFrame = newStartFrame;
40 45
41 if (dx == 0) { 46 if (dx == 0) {
42 // haven't moved visibly (even though start frame may have changed) 47 // haven't moved visibly (even though start frame may have changed)
48 count.hit();
43 return; 49 return;
44 } 50 }
45 51
46 int w = int(m_ranges.size()); 52 int w = int(m_ranges.size());
47 53
48 if (dx <= -w || dx >= w) { 54 if (dx <= -w || dx >= w) {
49 // scrolled entirely off 55 // scrolled entirely off
50 invalidate(); 56 invalidate();
57 count.miss();
51 return; 58 return;
52 } 59 }
60
61 count.partial();
53 62
54 // dx is in range, cache is scrollable 63 // dx is in range, cache is scrollable
55 64
56 if (dx < 0) { 65 if (dx < 0) {
57 // The new start frame is to the left of the old start 66 // The new start frame is to the left of the old start