2 Large image displaying library.
4 Copyright (C) 2004,2005 Maks Orlovich (maksim@kde.org)
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 namespace khtmlImLoad
{
38 //Interface to the cache LRU chains
39 TileCacheNode
* cacheNext
;
40 TileCacheNode
* cachePrev
;
44 cacheNext
->cachePrev
= cachePrev
;
45 cachePrev
->cacheNext
= cacheNext
;
50 void linkBefore(TileCacheNode
* node
)
52 this->cacheNext
= node
;
53 this->cachePrev
= node
->cachePrev
;
55 node
->cachePrev
= this;
56 this->cachePrev
->cacheNext
= this;
61 TileCacheNode(): cacheNext(0), cachePrev(0), tile(0)
67 An LRU-replacement cache for tiles.
72 typedef TileCacheNode Node
;
77 //### TODO: consider smarter allocation for these?.
82 Node
* toRet
= poolHead
;
83 poolHead
= poolHead
->cacheNext
;
90 void release(Node
* entry
)
93 entry
->cacheNext
= poolHead
;
102 We keep tiles in a double-linked list, with the most recent one being at the rear
108 Discard the node, and removes it from the list. Does not free the node.
110 void doDiscard(Node
* node
)
112 assert(node
->tile
->cacheNode
== node
);
113 node
->tile
->discard();
114 node
->tile
->cacheNode
= 0;
121 TileCache(int _sizeLimit
):sizeLimit(_sizeLimit
), size(0)
126 front
->cacheNext
= rear
;
127 rear
->cachePrev
= front
;
133 Add an entry to the cache.
135 void addEntry(Tile
* tile
)
137 assert (tile
->cacheNode
== 0);
142 if (size
>= sizeLimit
)
144 //Remove the front entry, reuse it
146 node
= front
->cacheNext
;
152 //Link in before the end sentinel, i.e. at the very last spot, increment usage count
154 tile
->cacheNode
= node
;
155 node
->linkBefore(rear
);
161 "Touches" the entry, making it the most recent
162 (i.e. moves the entry to the rear of the chain)
164 void touchEntry(Tile
* tile
)
166 Node
* node
= tile
->cacheNode
;
168 node
->linkBefore(rear
);
172 Removes the entry from the cache, discards it.
174 void removeEntry(Tile
* tile
)
176 Node
* node
= tile
->cacheNode
;
186 // kate: indent-width 4; replace-tabs on; tab-width 4; space-indent on;