-
Notifications
You must be signed in to change notification settings - Fork 253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
urls [nfc]: Pass around Uri
objects more (cut out some unneeded re-stringification)
#247
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks good; one nit below. In a commit message:
The most interesting consequence of this is that _LightboxHeroTag
now compares `src` using Uri's == operator override, instead of
string equality on the result of Uri.toString(). I expect that to
produce the same result, and at least as efficiently:
https://github.com/dart-lang/sdk/blob/9bf4af004/sdk/lib/core/uri.dart
It looks like specifically that's this:
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is Uri &&
scheme == other.scheme &&
hasAuthority == other.hasAuthority &&
userInfo == other.userInfo &&
host == other.host &&
port == other.port &&
path == other.path &&
hasQuery == other.hasQuery &&
query == other.query &&
hasFragment == other.hasFragment &&
fragment == other.fragment;
That looks slower to me than a string comparison — it's doing a bunch of separate string comparisons of different pieces. But it's fine, because this shouldn't be a hot path.
lib/widgets/lightbox.dart
Outdated
@@ -205,7 +205,7 @@ class _LightboxPageState extends State<_LightboxPage> { | |||
Route getLightboxRoute({ | |||
required BuildContext context, | |||
required Message message, | |||
required String src | |||
required Uri src |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
required Uri src | |
required Uri src, |
(since we're here)
The most interesting consequence of this is that _LightboxHeroTag now compares `src` using Uri's == operator override, instead of string equality on the result of Uri.toString(). Discussion: zulip#247 (review)
3da8c7e
to
f8893ec
Compare
Thanks for the review! Revision pushed.
I guess that makes sense. Each string comparison might come with some overhead, making it slower even if all the pieces add up to make the whole string. There's also this implementation: bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is Uri && _uri == other.toString();
} That's on |
The most interesting consequence of this is that _LightboxHeroTag now compares `src` using Uri's == operator override, instead of string equality on the result of Uri.toString(). Discussion: zulip#247 (review)
f8893ec
to
94aa9d1
Compare
Updated to change the type of |
Right, exactly. And even if the overhead is negligible, it won't be negative — the multiple-strings version won't be faster.
Hmm, yeah. Studying the parser a bit, it looks like most URLs we encounter are likely to end up as that Still not any faster than the string comparison, as the heart of it is just the same string comparison. |
This pushes the `toString` out to callers, so they can pass the string form to whatever other code is asking for it. ...Actually, though, in all the cases where that other code has been asking for the string form, it could easily be changed to accept the Uri form. So we'll do that, coming up.
The most interesting consequence of this is that _LightboxHeroTag now compares `src` using Uri's == operator override, instead of string equality on the result of Uri.toString(). Discussion: zulip#247 (review)
Thanks! Looks good; merging. |
94aa9d1
to
135cec1
Compare
Thanks! |
Hmm, did you accidentally clobber this part in the revision you merged?
extension RealmContentNetworkImageChecks on Subject<RealmContentNetworkImage> {
Subject<Uri> get src => has((i) => i.src, 'src');
// TODO others
} (with |
Oops, yeah. I must have not re-fetched after your last revision, and then not rerun tests after rebase. Please go ahead and send a fix, sorry. |
This was accidentally clobbered in the merge of zulip#247; see zulip#247 (comment)
Makes sense; just sent #257. |
Helpful anyway, I think, but this came up when thinking about avatar URLs, for #119.