Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c0df5c7 authored by Andreas Gampe's avatar Andreas Gampe
Browse files

Frameworks: Slightly refactor Parcel code

Decrease the amount of code covered by a lock in Parcel. This allows
fetching multiple classes in parallel, with the slight downside that
these classes might be the same.

Reduces contention samples for this method in profiling by two thirds.

Test: m
Test: manual profiling
Change-Id: I96415659f6625df25800c60dd3bee1094255fcc3
parent b50e778f
Loading
Loading
Loading
Loading
+53 −51
Original line number Diff line number Diff line
@@ -2797,14 +2797,19 @@ public final class Parcel {
            return null;
        }
        Parcelable.Creator<?> creator;
        HashMap<String, Parcelable.Creator<?>> map;
        synchronized (mCreators) {
            HashMap<String,Parcelable.Creator<?>> map = mCreators.get(loader);
            map = mCreators.get(loader);
            if (map == null) {
                map = new HashMap<>();
                mCreators.put(loader, map);
            }
            creator = map.get(name);
            if (creator == null) {
        }
        if (creator != null) {
            return creator;
        }

        try {
            // If loader == null, explicitly emulate Class.forName(String) "caller
            // classloader" behavior.
@@ -2832,18 +2837,15 @@ public final class Parcel {
                        + "CREATOR on class " + name);
            }
            creator = (Parcelable.Creator<?>) f.get(null);
                }
                catch (IllegalAccessException e) {
        } catch (IllegalAccessException e) {
            Log.e(TAG, "Illegal access when unmarshalling: " + name, e);
            throw new BadParcelableException(
                    "IllegalAccessException when unmarshalling: " + name);
                }
                catch (ClassNotFoundException e) {
        } catch (ClassNotFoundException e) {
            Log.e(TAG, "Class not found when unmarshalling: " + name, e);
            throw new BadParcelableException(
                    "ClassNotFoundException when unmarshalling: " + name);
                }
                catch (NoSuchFieldException e) {
        } catch (NoSuchFieldException e) {
            throw new BadParcelableException("Parcelable protocol requires a "
                    + "Parcelable.Creator object called "
                    + "CREATOR on class " + name);
@@ -2854,9 +2856,9 @@ public final class Parcel {
                    + "CREATOR on class " + name);
        }

        synchronized (mCreators) {
            map.put(name, creator);
        }
        }

        return creator;
    }