Comments (2)
bundleOf()
does not make Bundle().apply{}
irrelevant. The extra allocations created by the Pair
should not have a meaningful impact on apps unless they store thousands of items in bundles (which would indicate other issues). Short-lived allocations like this are also fairly well optimized out in N and O.
from android-ktx.
(Whoops I had a reply to this in a tab and forgot to hit enter.)
The full transformation with all syntactic niceties becomes:
bundleOf(
KEY_ANSWER_ONE to answerOne?.text?.toString(),
KEY_ANSWER_TWO to answerTwo?.text?.toString())
This syntax matches that of the various *Of
factories in the stdlib which take pairs (e.g., mapOf
, mutableMapOf
, and our provided arrayMapOf
).
One advantage to the allocation here is that the underlying collection can be pre-sized to exactly fit. This avoids it always starting empty, going through an allocation to 4 slots, and then having to double (based on how many elements you add).
Allocations like this wind up in many APIs. Hopefully someday the compiler will be able to see through the varargs and pair allocations someday. Or we could try getting the optimizations into D8, R8, or even ART.
The runtime check is the most unfortunate part, but as of yet there's no way to optimize it. We can bundle lint checks for it, though.
from android-ktx.
Related Issues (20)
- Convenience DSL for Media Controller Callback event handling
- androidx.preference.PreferenceFragment not derived from androidx.fragment.app.Fragment HOT 2
- Manifest merger failed HOT 5
- Release of 1.0.0-alpha3 out of sync with this repo HOT 4
- Extension property of bitmap from ImageView HOT 1
- error: resource android:attr/fontVariationSettings not found. HOT 1
- ImageDecoder source and test issues HOT 7
- inline extension properties can't be used in SAM lambda functions due to compiler bug HOT 1
- Add popular libraries extensions in new module HOT 1
- AAPT2 Error HOT 1
- View.post with with this view as a parameter HOT 2
- Resources.Theme.resolveAttribute extension
- Improve View.doOnPreDraw(...) HOT 1
- Features suggestions: Live data transformation HOT 1
- Offer: AsyncTask replacement
- Can't use getString(String) : String HOT 2
- androidx.core.os.BundleKt.bundleOf: Imports for API 21 classes break on older devices HOT 2
- gradle error HOT 3
- Add support for manipulating a color as HSV HOT 1
- Hi everyone!
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-ktx.