@@ -88,13 +88,9 @@ private void SetSpacesTimestamp(IReadOnlyCollection<string> spaces, long ts)
88
88
if ( spaces . Count == 0 )
89
89
return ;
90
90
91
- var timestamps = new object [ spaces . Count ] ;
92
- for ( var i = 0 ; i < timestamps . Length ; i ++ )
93
- {
94
- timestamps [ i ] = ts ;
95
- }
96
-
97
- _updateTimestamps . PutMany ( spaces . ToArray ( ) , timestamps ) ;
91
+ _updateTimestamps . PutMany (
92
+ spaces . ToArray < object > ( ) ,
93
+ ArrayHelper . Fill < object > ( ts , spaces . Count ) ) ;
98
94
}
99
95
100
96
[ MethodImpl ( MethodImplOptions . Synchronized ) ]
@@ -103,49 +99,34 @@ public virtual bool IsUpToDate(ISet<string> spaces, long timestamp /* H2.1 has L
103
99
if ( spaces . Count == 0 )
104
100
return true ;
105
101
106
- var keys = new object [ spaces . Count ] ;
107
- var index = 0 ;
108
- foreach ( var space in spaces )
109
- {
110
- keys [ index ++ ] = space ;
111
- }
112
- var lastUpdates = _updateTimestamps . GetMany ( keys ) ;
102
+ var lastUpdates = _updateTimestamps . GetMany ( spaces . ToArray < object > ( ) ) ;
113
103
return lastUpdates . All ( lastUpdate => ! IsOutdated ( lastUpdate as long ? , timestamp ) ) ;
114
104
}
115
105
116
106
[ MethodImpl ( MethodImplOptions . Synchronized ) ]
117
107
public virtual bool [ ] AreUpToDate ( ISet < string > [ ] spaces , long [ ] timestamps )
118
108
{
119
- var results = new bool [ spaces . Length ] ;
109
+ if ( spaces . Length == 0 )
110
+ return Array . Empty < bool > ( ) ;
111
+
120
112
var allSpaces = new HashSet < string > ( ) ;
121
113
foreach ( var sp in spaces )
122
114
{
123
115
allSpaces . UnionWith ( sp ) ;
124
116
}
125
117
126
118
if ( allSpaces . Count == 0 )
127
- {
128
- for ( var i = 0 ; i < spaces . Length ; i ++ )
129
- {
130
- results [ i ] = true ;
131
- }
119
+ return ArrayHelper . Fill ( true , spaces . Length ) ;
132
120
133
- return results ;
134
- }
121
+ var keys = allSpaces . ToArray < object > ( ) ;
135
122
136
- var keys = new object [ allSpaces . Count ] ;
137
123
var index = 0 ;
138
- foreach ( var space in allSpaces )
139
- {
140
- keys [ index ++ ] = space ;
141
- }
142
-
143
- index = 0 ;
144
124
var lastUpdatesBySpace =
145
125
_updateTimestamps
146
126
. GetMany ( keys )
147
127
. ToDictionary ( u => keys [ index ++ ] , u => u as long ? ) ;
148
128
129
+ var results = new bool [ spaces . Length ] ;
149
130
for ( var i = 0 ; i < spaces . Length ; i ++ )
150
131
{
151
132
var timestamp = timestamps [ i ] ;
@@ -163,7 +144,7 @@ public virtual void Destroy()
163
144
// not the responsibility of this class.
164
145
}
165
146
166
- private bool IsOutdated ( long ? lastUpdate , long timestamp )
147
+ private static bool IsOutdated ( long ? lastUpdate , long timestamp )
167
148
{
168
149
if ( ! lastUpdate . HasValue )
169
150
{
0 commit comments