Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: pkg/analysis_server/lib/src/index/page_node_manager.dart

Issue 331603002: Fix caching paging during read. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library index.page_node_manager; 5 library index.page_node_manager;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:typed_data'; 8 import 'dart:typed_data';
9 9
10 import 'package:analysis_server/src/index/b_plus_tree.dart';
10 import 'package:analysis_server/src/index/lru_cache.dart'; 11 import 'package:analysis_server/src/index/lru_cache.dart';
11 12
12 import 'b_plus_tree.dart';
13
14 13
15 /** 14 /**
16 * A [NodeManager] that caches a specified number of index and leaf nodes. 15 * A [NodeManager] that caches a specified number of index and leaf nodes.
17 */ 16 */
18 class CachingNodeManager<K, V, N> implements NodeManager<K, V, N> { 17 class CachingNodeManager<K, V, N> implements NodeManager<K, V, N> {
19 final NodeManager<K, V, N> _delegate; 18 final NodeManager<K, V, N> _delegate;
20 LRUCache<N, IndexNodeData<K, N>> _indexCache; 19 LRUCache<N, IndexNodeData<K, N>> _indexCache;
21 LRUCache<N, LeafNodeData<K, V>> _leafCache; 20 LRUCache<N, LeafNodeData<K, V>> _leafCache;
22 21
23 CachingNodeManager(this._delegate, int indexNodeCacheSize, 22 CachingNodeManager(this._delegate, int indexNodeCacheSize,
(...skipping 28 matching lines...) Expand all
52 } 51 }
53 52
54 @override 53 @override
55 bool isIndex(N id) { 54 bool isIndex(N id) {
56 return _delegate.isIndex(id); 55 return _delegate.isIndex(id);
57 } 56 }
58 57
59 @override 58 @override
60 IndexNodeData<K, N> readIndex(N id) { 59 IndexNodeData<K, N> readIndex(N id) {
61 IndexNodeData<K, N> data = _indexCache.get(id); 60 IndexNodeData<K, N> data = _indexCache.get(id);
62 if (data != null) { 61 if (data == null) {
63 return data; 62 data = _delegate.readIndex(id);
63 _indexCache.put(id, data);
64 } 64 }
65 return _delegate.readIndex(id); 65 return data;
66 } 66 }
67 67
68 @override 68 @override
69 LeafNodeData<K, V> readLeaf(N id) { 69 LeafNodeData<K, V> readLeaf(N id) {
70 LeafNodeData<K, V> data = _leafCache.get(id); 70 LeafNodeData<K, V> data = _leafCache.get(id);
71 if (data != null) { 71 if (data == null) {
72 return data; 72 data = _delegate.readLeaf(id);
73 _leafCache.put(id, data);
73 } 74 }
74 return _delegate.readLeaf(id); 75 return data;
75 } 76 }
76 77
77 @override 78 @override
78 void writeIndex(N id, IndexNodeData<K, N> data) { 79 void writeIndex(N id, IndexNodeData<K, N> data) {
79 _indexCache.put(id, data); 80 _indexCache.put(id, data);
80 } 81 }
81 82
82 @override 83 @override
83 void writeLeaf(N id, LeafNodeData<K, V> data) { 84 void writeLeaf(N id, LeafNodeData<K, V> data) {
84 _leafCache.put(id, data); 85 _leafCache.put(id, data);
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 @override 452 @override
452 int decode(ByteData buffer) { 453 int decode(ByteData buffer) {
453 return buffer.getUint32(0); 454 return buffer.getUint32(0);
454 } 455 }
455 456
456 @override 457 @override
457 void encode(ByteData buffer, int element) { 458 void encode(ByteData buffer, int element) {
458 buffer.setUint32(0, element); 459 buffer.setUint32(0, element);
459 } 460 }
460 } 461 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/index/b_plus_tree.dart ('k') | pkg/analysis_server/test/index/page_node_manager_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698