From 5f5ec7b8d58bf90f16ea0b64e5e7a6da86b98aff Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Wed, 29 Mar 2017 18:06:46 +0100 Subject: [PATCH] Avoid unnecessary object allocation in CryptoInfo.set This is causing a large number of unnecessary small object allocations during encrypted playbacks, which presumably all need to be GC'd. I wasn't sure whether the zero pattern should be static; that might be objectionable in the platform (unsure?), since it would live forever from the point of the class being classloaded. It doesn't make much/any difference in practice in any case. Test: Safe refactoring CL. Change-Id: I9ee5fe284b0f854d672d83b97fc51116b0416f91 --- media/java/android/media/MediaCodec.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/media/java/android/media/MediaCodec.java b/media/java/android/media/MediaCodec.java index 13a22b49ff87b..9a38dda1a733b 100644 --- a/media/java/android/media/MediaCodec.java +++ b/media/java/android/media/MediaCodec.java @@ -2441,6 +2441,8 @@ final public class MediaCodec { } }; + private final Pattern zeroPattern = new Pattern(0, 0); + /** * The pattern applicable to the protected data in each subsample. */ @@ -2463,7 +2465,7 @@ final public class MediaCodec { key = newKey; iv = newIV; mode = newMode; - pattern = new Pattern(0, 0); + pattern = zeroPattern; } /**