private _markEntryAsUsed()

in packages/shared/src/lru.ts [57:81]


  private _markEntryAsUsed(entry: any) {
    if (entry === this.newest) {
      // Already the most recenlty used entry, so no need to update the list
      return
    }
    // HEAD--------------TAIL
    //   <.older   .newer>
    //  <--- add direction --
    //   A  B  C  <D>  E
    if (entry[NEWER]) {
      if (entry === this.oldest) {
        this.oldest = entry[NEWER]
      }
      entry[NEWER][OLDER] = entry[OLDER] // C <-- E.
    }
    if (entry[OLDER]) {
      entry[OLDER][NEWER] = entry[NEWER] // C. --> E
    }
    entry[NEWER] = undefined // D --x
    entry[OLDER] = this.newest // D. --> E
    if (this.newest) {
      this.newest[NEWER] = entry // E. <-- D
    }
    this.newest = entry
  }