这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Sep 2, 2020. It is now read-only.
This repository was archived by the owner on Sep 2, 2020. It is now read-only.

Return a immutable singleton for Task.forResult(null) and Task.cancelled() #82

@grantland

Description

@grantland

Currently each call to Task.forResult(null) and Task.cancelled() create new instances of Task and TaskCompletionSource, which are exactly the same for each execution.

These methods can be extremely common in codebases, especially Task.forResult(null), which is used internally in Bolts-Android and Parse-SDK-Android from converting null return values in continuations to stubbing non-asynchronous methods with an asynchronous method signature.

We can optimize these calls by reusing the same value and reduce the amount of memory allocated in applications relying on Bolts and we can do this since each return value is equivalent and essentially immutable.

/cc @nlutsenko

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions