Skip to content

Conversation

@HansMuller
Copy link
Contributor

If variants are found for an asset then we don't require that the "main" asset's file exists.

Replaced the N-squared algorithm that matches assets and variants; now it's O(N).

Fixes #8231

@Hixie
Copy link
Contributor

Hixie commented Jun 22, 2017

You might also need to update dartdocs in various places, comments in the pubspec.yaml.tmpl file, and various things on our Web site.

@HansMuller
Copy link
Contributor Author

HansMuller commented Jun 22, 2017

I have updated the pubspec.yaml file and will have to update the web site (https://flutter.io/assets-and-images/.) separately.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

printError('$e'); is probably more idiomatic. Hopefully it isn't slower. :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an invariant at this point, or is this the place where you're checking that the input is valid?
Asserts won't always run in flutter_tools, since we sometimes run it in release mode.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is just an invariant that you're checking, leave a comment pointing to where we do the input validation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original version of this check had been an invariant but it probably should throw an error. With a mighty helpful error message :-).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variantsFor takes a single string, but you're passing two here, did you mean 'assets/foo'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, yes. I'd forgotten to update the doc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is O(N*M), could _excluded be a Set somehow? I guess the right data structure here is a prefix tree, but that may be going off into the weeds a bit prematurely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can just substitute an ordinary loop over the file system entities that builds the list of paths.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing a loop here saves the cost of creating a list of paths and then a copy of that after filtering out the excluded paths. The excluded list is length 2, I think that's probably enough tweaking.

@Hixie
Copy link
Contributor

Hixie commented Jun 22, 2017

LGTM (mostly... a bit RSLGTM, @tvolkert may be a better reviewer).

The only suggestion I would have is to add an end-to-end test (in the devicelab) that verifies that this works (i.e. that if you only have 2x and 3x variants, on a 1x device, you get the 2x variant).

Hixie added a commit to flutter/website that referenced this pull request Jun 22, 2017
This assumes that flutter/flutter#10901 will land.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assetVariants can't be empty, since we're iterating through it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, that was supposed to be assetVariants[asset].isEmpty

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... which makes this if check redundant

@HansMuller HansMuller merged commit b55441a into flutter:master Jun 22, 2017
@HansMuller HansMuller deleted the asset_variants branch June 22, 2017 23:46
Hixie added a commit to flutter/website that referenced this pull request Jun 23, 2017
gspencergoog pushed a commit to gspencergoog/flutter that referenced this pull request Jul 1, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolution-aware Assets require 1x

4 participants