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

Commit 3a5da035 authored by Kweku Adams's avatar Kweku Adams
Browse files

Avoid overallocating array size.

Since namespaces can just be a subset of jobs, don't allocate the
ArrayList to fit all jobs of the app.

Bug: 141645789
Test: atest CtsJobSchedulerTestCases
Change-Id: I801ee2b47b1735f7994c3c121da5aba34ede4b3d
parent 9d1c9281
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -1588,12 +1588,12 @@ public class JobSchedulerService extends com.android.server.SystemService
        final ArrayMap<String, List<JobInfo>> outMap = new ArrayMap<>();
        synchronized (mLock) {
            ArraySet<JobStatus> jobs = mJobs.getJobsByUid(uid);
            // Write out for loop to avoid addAll() creating an Iterator.
            // Write out for loop to avoid creating an Iterator.
            for (int i = jobs.size() - 1; i >= 0; i--) {
                final JobStatus job = jobs.valueAt(i);
                List<JobInfo> outList = outMap.get(job.getNamespace());
                if (outList == null) {
                    outList = new ArrayList<JobInfo>(jobs.size());
                    outList = new ArrayList<>();
                    outMap.put(job.getNamespace(), outList);
                }

@@ -1606,7 +1606,7 @@ public class JobSchedulerService extends com.android.server.SystemService
    private List<JobInfo> getPendingJobsInNamespace(int uid, @Nullable String namespace) {
        synchronized (mLock) {
            ArraySet<JobStatus> jobs = mJobs.getJobsByUid(uid);
            ArrayList<JobInfo> outList = new ArrayList<JobInfo>(jobs.size());
            ArrayList<JobInfo> outList = new ArrayList<>();
            // Write out for loop to avoid addAll() creating an Iterator.
            for (int i = jobs.size() - 1; i >= 0; i--) {
                final JobStatus job = jobs.valueAt(i);