File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed
src/main/java/io/github/nstdio/http/ext Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change 1616
1717package io .github .nstdio .http .ext ;
1818
19- import java .util .*;
19+ import java .util .ArrayList ;
20+ import java .util .Collections ;
21+ import java .util .Iterator ;
22+ import java .util .LinkedHashMap ;
23+ import java .util .List ;
24+ import java .util .Map ;
2025import java .util .function .Consumer ;
2126import java .util .function .ToIntFunction ;
2227
@@ -60,7 +65,7 @@ V getSingle(K k, ToIntFunction<List<V>> idxFn) {
6065 }
6166
6267 List <V > putSingle (K key , V value , ToIntFunction <List <V >> idxFn ) {
63- List <V > vs = m .computeIfAbsent (key , k -> new ArrayList <>());
68+ List <V > vs = m .computeIfAbsent (key , k -> new ArrayList <>(1 ));
6469
6570 int i ;
6671 if (!vs .isEmpty () && (i = idxFn .applyAsInt (vs )) != -1 ) {
@@ -107,10 +112,12 @@ private V removeEldest(List<V> vs) {
107112 void evictAll (K k ) {
108113 List <V > old = m .remove (k );
109114 if (old != null ) {
110- while (! old .isEmpty ()) {
111- notifyEvicted ( removeEldest ( old ));
112- size -- ;
115+ int len = old .size ();
116+ for ( int i = len - 1 ; i >= 0 ; i --) {
117+ notifyEvicted ( old . get ( i )) ;
113118 }
119+
120+ this .size -= len ;
114121 }
115122 }
116123
You can’t perform that action at this time.
0 commit comments