@@ -172,8 +172,8 @@ Object lruCacheNew(VirtualFrame frame, Object type,
172172
173173 LruCacheObject obj = factory ().createLruCacheObject (type );
174174
175- obj .prev = obj ;
176- obj .next = obj ;
175+ obj .root . prev = obj . root ;
176+ obj .root . next = obj . root ;
177177 obj .wrapper = wrapper ;
178178 obj .typed = typed ;
179179 // obj.cache = new ObjectHashMap();
@@ -184,8 +184,6 @@ Object lruCacheNew(VirtualFrame frame, Object type,
184184
185185 obj .kwdMark = getKwdMark (readAttr );
186186
187- // obj.lru_list_elem_type = state.lru_list_elem_type;
188-
189187 obj .cacheInfoType = cache_info_type ;
190188 // obj.dict = null;
191189 // obj.weakreflist = null;
@@ -370,7 +368,7 @@ static void lru_cache_prepend_link(LruCacheObject self, LruListElemObject link)
370368
371369 // lru_cache_append_link
372370 static void lruCacheAppendLink (LruCacheObject self , LruListElemObject link ) {
373- LruListElemObject root = self ;
371+ LruListElemObject root = self . root ;
374372 LruListElemObject last = root .prev ;
375373 last .next = root .prev = link ;
376374 link .prev = last ;
@@ -434,10 +432,6 @@ Object boundedLruCacheWrapper(VirtualFrame frame, LruCacheObject self, Object[]
434432 self .hits ++;
435433 return link .result ;
436434 }
437- // mq: this might be needed if self.cache is a dict
438- // if (PyErr_Occurred()) {
439- // return NULL;
440- // }
441435 self .misses ++;
442436 Object result = callNode .execute (frame , self .func , args , kwds );
443437 Object testresult = getItem .get (frame , self .cache , key , hash );
@@ -449,23 +443,15 @@ Object boundedLruCacheWrapper(VirtualFrame frame, LruCacheObject self, Object[]
449443 */
450444 return result ;
451445 }
452- // mq: this will only occur if the cache is a dict.
453- // if (PyErr_Occurred()) {
454- // /* This is an unusual case since this same lookup
455- // did not previously trigger an error during lookup.
456- // Treat it the same as an error in user function
457- // and return with the error set. */
458- // return NULL;
459- // }
460446 /*
461447 * This is the normal case. The new key wasn't found before user function call and it is
462448 * still not there. So we proceed normally and update the cache with the new result.
463449 */
464450
465451 assert (self .maxsize > 0 );
466- if (self .cache .size () < self .maxsize || self .next == self ) {
452+ if (self .cache .size () < self .maxsize || self .root . next == self . root ) {
467453 /* Cache is not full, so put the result in a new link */
468- link = factory (). createLruListElemObject ();
454+ link = new LruListElemObject ();
469455
470456 link .hash = hash ;
471457 link .key = key ;
@@ -494,7 +480,7 @@ Object boundedLruCacheWrapper(VirtualFrame frame, LruCacheObject self, Object[]
494480
495481 /* Extract the oldest item. */
496482 // assert (self.next != self);
497- link = self .next ;
483+ link = self .root . next ;
498484 lruCacheExtractLink (link );
499485 /*
500486 * Remove it from the cache. The cache dict holds one reference to the link. We created
@@ -544,7 +530,7 @@ public abstract static class ClearNode extends PythonUnaryBuiltinNode {
544530
545531 // lru_cache_unlink_list
546532 static LruListElemObject lruCacheUnlinkList (LruCacheObject self ) {
547- LruListElemObject root = self ;
533+ LruListElemObject root = self . root ;
548534 LruListElemObject link = root .next ;
549535 if (link == root ) {
550536 return null ;
0 commit comments