frankiesardo / icepick

Android Instance State made easy
Eclipse Public License 1.0
3.75k stars 208 forks source link

Differentiate INJECTORS cache hit of null vs not present #96

Closed elihart closed 7 years ago

elihart commented 7 years ago

Icepick.getInjector looks for an injector cache hit with

Injector var1 = (Injector)INJECTORS.get(var0);
        if(var1 != null) {
            if(debug) {
                Log.d("Icepick", "HIT: Cached in injector map.");
            }

            return var1;
        } 

The problem is that even if the Injectors map contains the value, but it is null, it is not considered a hit. Then the injector is looked up again.

We have a base fragment used across our app that applies icepick to all subclasses, but not all of those subclasses have saved state. In those cases Icepick constantly searches for the injector.

A simple INJECTORS.contains check would help this case and improve performance.

frankiesardo commented 7 years ago

Thanks

elihart commented 7 years ago

Thanks for fixing @frankiesardo! any plans to make a new release that includes this?