frameworks/base: Avoid Long object allocations in Long.valueOf()

Replace usages where the Long is immediately unboxed or thrown
away with Long.parseLong().
In TaskRecord.java, I also fixed up similar uses of
{Boolean,Integer}.valueOf()

Tested: built frameworks/base successfully.

Bug: 28289401
Change-Id: I1fad536853a68c7b0707cbf02989aca155064843
This commit is contained in:
Tobias Thierer
2016-04-21 14:52:10 +01:00
parent 570a13f0cb
commit 4bd017d6a5
13 changed files with 36 additions and 36 deletions

View File

@@ -527,7 +527,7 @@ public class Am extends BaseCommand {
String[] strings = value.split(",");
long[] list = new long[strings.length];
for (int i = 0; i < strings.length; i++) {
list[i] = Long.valueOf(strings[i]);
list[i] = Long.parseLong(strings[i]);
}
intent.putExtra(key, list);
hasIntentInfo = true;

View File

@@ -128,15 +128,15 @@ public class RequestSync {
} else if (opt.equals("--el") || opt.equals("--extra-long")) {
final String key = nextArgRequired();
final String value = nextArgRequired();
mExtras.putLong(key, Long.valueOf(value));
mExtras.putLong(key, Long.parseLong(value));
} else if (opt.equals("--ef") || opt.equals("--extra-float")) {
final String key = nextArgRequired();
final String value = nextArgRequired();
mExtras.putFloat(key, Long.valueOf(value));
mExtras.putFloat(key, Long.parseLong(value));
} else if (opt.equals("--ed") || opt.equals("--extra-double")) {
final String key = nextArgRequired();
final String value = nextArgRequired();
mExtras.putFloat(key, Long.valueOf(value));
mExtras.putFloat(key, Long.parseLong(value));
} else if (opt.equals("--ez") || opt.equals("--extra-bool")) {
final String key = nextArgRequired();
final String value = nextArgRequired();

View File

@@ -453,7 +453,7 @@ public final class NfcFCardEmulation {
return false;
}
try {
Long.valueOf(nfcid2, 16);
Long.parseLong(nfcid2, 16);
} catch (NumberFormatException e) {
Log.e(TAG, "NFCID2 " + nfcid2 + " is not a valid NFCID2.");
return false;

View File

@@ -364,7 +364,7 @@ public class ZenModeConfig implements Parcelable {
private static long tryParseLong(String value, long defValue) {
if (TextUtils.isEmpty(value)) return defValue;
try {
return Long.valueOf(value);
return Long.parseLong(value);
} catch (NumberFormatException e) {
return defValue;
}

View File

@@ -386,7 +386,7 @@ public class ExifInterface {
String subSecs = mAttributes.get(TAG_SUBSECTIME);
if (subSecs != null) {
try {
long sub = Long.valueOf(subSecs);
long sub = Long.parseLong(subSecs);
while (sub > 1000) {
sub /= 10;
}

View File

@@ -563,7 +563,7 @@ final class SettingsState {
}
public Setting(String name, String value, String packageName, String id) {
mNextId = Math.max(mNextId, Long.valueOf(id) + 1);
mNextId = Math.max(mNextId, Long.parseLong(id) + 1);
init(name, value, packageName, id);
}

View File

@@ -567,7 +567,7 @@ public final class DropBoxManagerService extends IDropBoxManagerService.Stub {
this.flags = flags;
long millis;
try { millis = Long.valueOf(name); } catch (NumberFormatException e) { millis = 0; }
try { millis = Long.parseLong(name); } catch (NumberFormatException e) { millis = 0; }
this.timestampMillis = millis;
}

View File

@@ -1210,7 +1210,7 @@ final class ActivityRecord {
if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
"ActivityRecord: attribute name=" + attrName + " value=" + attrValue);
if (ATTR_ID.equals(attrName)) {
createTime = Long.valueOf(attrValue);
createTime = Long.parseLong(attrValue);
} else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) {
launchedFromUid = Integer.valueOf(attrValue);
} else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) {

View File

@@ -1018,7 +1018,7 @@ final class TaskRecord {
if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "TaskRecord: attribute name=" +
attrName + " value=" + attrValue);
if (ATTR_TASKID.equals(attrName)) {
if (taskId == INVALID_TASK_ID) taskId = Integer.valueOf(attrValue);
if (taskId == INVALID_TASK_ID) taskId = Integer.parseInt(attrValue);
} else if (ATTR_REALACTIVITY.equals(attrName)) {
realActivity = ComponentName.unflattenFromString(attrValue);
} else if (ATTR_ORIGACTIVITY.equals(attrName)) {
@@ -1029,45 +1029,45 @@ final class TaskRecord {
rootAffinity = attrValue;
hasRootAffinity = true;
} else if (ATTR_ROOTHASRESET.equals(attrName)) {
rootHasReset = Boolean.valueOf(attrValue);
rootHasReset = Boolean.parseBoolean(attrValue);
} else if (ATTR_AUTOREMOVERECENTS.equals(attrName)) {
autoRemoveRecents = Boolean.valueOf(attrValue);
autoRemoveRecents = Boolean.parseBoolean(attrValue);
} else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) {
askedCompatMode = Boolean.valueOf(attrValue);
askedCompatMode = Boolean.parseBoolean(attrValue);
} else if (ATTR_USERID.equals(attrName)) {
userId = Integer.valueOf(attrValue);
userId = Integer.parseInt(attrValue);
} else if (ATTR_EFFECTIVE_UID.equals(attrName)) {
effectiveUid = Integer.valueOf(attrValue);
effectiveUid = Integer.parseInt(attrValue);
} else if (ATTR_TASKTYPE.equals(attrName)) {
taskType = Integer.valueOf(attrValue);
taskType = Integer.parseInt(attrValue);
} else if (ATTR_FIRSTACTIVETIME.equals(attrName)) {
firstActiveTime = Long.valueOf(attrValue);
firstActiveTime = Long.parseLong(attrValue);
} else if (ATTR_LASTACTIVETIME.equals(attrName)) {
lastActiveTime = Long.valueOf(attrValue);
lastActiveTime = Long.parseLong(attrValue);
} else if (ATTR_LASTDESCRIPTION.equals(attrName)) {
lastDescription = attrValue;
} else if (ATTR_LASTTIMEMOVED.equals(attrName)) {
lastTimeOnTop = Long.valueOf(attrValue);
lastTimeOnTop = Long.parseLong(attrValue);
} else if (ATTR_NEVERRELINQUISH.equals(attrName)) {
neverRelinquishIdentity = Boolean.valueOf(attrValue);
neverRelinquishIdentity = Boolean.parseBoolean(attrValue);
} else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
taskDescription.restoreFromXml(attrName, attrValue);
} else if (ATTR_TASK_AFFILIATION.equals(attrName)) {
taskAffiliation = Integer.valueOf(attrValue);
taskAffiliation = Integer.parseInt(attrValue);
} else if (ATTR_PREV_AFFILIATION.equals(attrName)) {
prevTaskId = Integer.valueOf(attrValue);
prevTaskId = Integer.parseInt(attrValue);
} else if (ATTR_NEXT_AFFILIATION.equals(attrName)) {
nextTaskId = Integer.valueOf(attrValue);
nextTaskId = Integer.parseInt(attrValue);
} else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) {
taskAffiliationColor = Integer.valueOf(attrValue);
taskAffiliationColor = Integer.parseInt(attrValue);
} else if (ATTR_CALLING_UID.equals(attrName)) {
callingUid = Integer.valueOf(attrValue);
callingUid = Integer.parseInt(attrValue);
} else if (ATTR_CALLING_PACKAGE.equals(attrName)) {
callingPackage = attrValue;
} else if (ATTR_RESIZEABLE.equals(attrName)) {
resizeable = Boolean.valueOf(attrValue);
resizeable = Boolean.parseBoolean(attrValue);
} else if (ATTR_PRIVILEGED.equals(attrName)) {
privileged = Boolean.valueOf(attrValue);
privileged = Boolean.parseBoolean(attrValue);
} else {
Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName);
}

View File

@@ -568,7 +568,7 @@ public class JobStore {
if (XML_TAG_PERIODIC.equals(parser.getName())) {
try {
String val = parser.getAttributeValue(null, "period");
final long periodMillis = Long.valueOf(val);
final long periodMillis = Long.parseLong(val);
jobBuilder.setPeriodic(periodMillis);
// As a sanity check, cap the recreated run time to be no later than 2 periods
// from now. This is the latest the periodic could be pushed out. This could
@@ -675,7 +675,7 @@ public class JobStore {
private void maybeBuildBackoffPolicyFromXml(JobInfo.Builder jobBuilder, XmlPullParser parser) {
String val = parser.getAttributeValue(null, "initial-backoff");
if (val != null) {
long initialBackoff = Long.valueOf(val);
long initialBackoff = Long.parseLong(val);
val = parser.getAttributeValue(null, "backoff-policy");
int backoffPolicy = Integer.valueOf(val); // Will throw NFE which we catch higher up.
jobBuilder.setBackoffCriteria(initialBackoff, backoffPolicy);
@@ -698,14 +698,14 @@ public class JobStore {
long latestRunTimeElapsed = JobStatus.NO_LATEST_RUNTIME;
String val = parser.getAttributeValue(null, "deadline");
if (val != null) {
long latestRuntimeWallclock = Long.valueOf(val);
long latestRuntimeWallclock = Long.parseLong(val);
long maxDelayElapsed =
Math.max(latestRuntimeWallclock - nowWallclock, 0);
latestRunTimeElapsed = nowElapsed + maxDelayElapsed;
}
val = parser.getAttributeValue(null, "delay");
if (val != null) {
long earliestRuntimeWallclock = Long.valueOf(val);
long earliestRuntimeWallclock = Long.parseLong(val);
long minDelayElapsed =
Math.max(earliestRuntimeWallclock - nowWallclock, 0);
earliestRunTimeElapsed = nowElapsed + minDelayElapsed;

View File

@@ -3530,7 +3530,7 @@ public class NotificationManagerService extends SystemService {
filter.stats = true;
if (ai < args.length-1) {
ai++;
filter.since = Long.valueOf(args[ai]);
filter.since = Long.parseLong(args[ai]);
} else {
filter.since = 0;
}

View File

@@ -134,11 +134,11 @@ public class MainActivity extends Activity {
String delay = mDelayEditText.getText().toString();
if (delay != null && !TextUtils.isEmpty(delay)) {
builder.setMinimumLatency(Long.valueOf(delay) * 1000);
builder.setMinimumLatency(Long.parseLong(delay) * 1000);
}
String deadline = mDeadlineEditText.getText().toString();
if (deadline != null && !TextUtils.isEmpty(deadline)) {
builder.setOverrideDeadline(Long.valueOf(deadline) * 1000);
builder.setOverrideDeadline(Long.parseLong(deadline) * 1000);
}
boolean requiresUnmetered = mWiFiConnectivityRadioButton.isChecked();
boolean requiresAnyConnectivity = mAnyConnectivityRadioButton.isChecked();

View File

@@ -214,7 +214,7 @@ public class TrackerService extends Service {
private long getLocationUpdateTime() {
try {
String timeString = getPreferences().getString(MIN_TIME_PREF, "0");
long secondsTime = Long.valueOf(timeString);
long secondsTime = Long.parseLong(timeString);
return secondsTime * 1000;
}
catch (NumberFormatException e) {