Skip to content

Instantly share code, notes, and snippets.

@NightlyNexus
Created March 24, 2017 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NightlyNexus/ff5c1e8f9e7c567efb349d499460d973 to your computer and use it in GitHub Desktop.
Save NightlyNexus/ff5c1e8f9e7c567efb349d499460d973 to your computer and use it in GitHub Desktop.
class View {
Data data;
void setData(Data data) {
this.data = data;
setOnClickListener(v -> run(data));
}
}
class View {
Data data;
private final View.OnClickListener clickListener = new OnClickListener() {
@Override public void onClick(View v) { run(data);}
};
{ setOnClickListener(clickListener); }
void setData(Data data) { this.data = data; }
}
@JakeWharton
Copy link

The former allocates on every invocation of bind. When flinging you don't want it to waste time allocating in the draw path.

@NightlyNexus
Copy link
Author

I mean, how many objects does Picasso.load allocate while I'm flinging?
But, every piece counts, and I should reduce waste when I know it's going to be used in this manner. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment