mattwar / iqtoolkit

A Toolkit for building LINQ IQueryable providers. This is the official move of my IQToolkit project from CodePlex.
Other
237 stars 77 forks source link

MostRecentlyUsedCache #10

Closed MarkusTischendorf closed 6 years ago

MarkusTischendorf commented 7 years ago

Hi Matt,

i think there is an issue in the MastRecentlyUsedCache class in method Lookup.

The method is always returing the last query not the one it found:

for (int i = 0, n = this.list.Count; i < n; i++)
{
    cached = this.list[i];

    if (fnEquals(cached, item))
    {
         cacheIndex = 0;
    }
}

I think this should be correct:

for (int i = 0, n = list.Count; i < n && cacheIndex < 0; i++)
{
    cached = this.list[i];

    if (_fnEquals(cached, item))
    {
        cacheIndex = i;
    }
}

The for-loop is two times in that method.

Thanks and best regards,

Markus

mattwar commented 6 years ago

Yes, that code was wrong. bad code!

As far as I can tell, it was returning the found item, it was just never updating the MRU list.

I really need some unit tests for these common classes. 😞

I've fixed it with this change: https://github.com/mattwar/iqtoolkit/pull/11/commits/a708c62d6646f5156de5970a18626c4cec2fe096