-
Notifications
You must be signed in to change notification settings - Fork 14
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
Avoid getting Version
/Channel
/Date
information more than once.
#21
Comments
For an example of the re-reading I'm talking about, see the |
This isn't true. Any non-static methods you call on these structures don't read any information from the system. They don't need to: these are parsed structures that contain all of the relevant information. The same is true for each individual structure obtained via the struct's
They already have methods to query them. |
The one exception is the We could add another structure, say |
Thanks for clarifying the API! I think I was tripped up by the inconsistent naming between the free functions on the methods on the |
Right now, subsequent calls to functions like
supports_feature
result inChannel
beingread
multiple times, which means aCommand
gets constructed and run. Relatedly, whiletriple
gets you a(Version, Channel, Date)
, there's not much you can do with those values, as the exposed API willread
fresh ones anyway when you ask questions.Some options for changing this:
1. TLS Cache
Keep the API the same but add some thread-local-storage
std::sync::Once
values for theVersion
,Channel
, andDate
, to cache the result and avoid loading them again.2. New
Rustc
TypeIntroduce a new
Rustc
struct that looks like:Then expose the currently-free functions on it, and have them lazily store the values they get into the struct, returning them again on subsequent calls rather than re-reading them. This is basically like the first option, but avoids thread-local storage.
This also lets you keep the current API, and just add the
Rustc
type for people who want to avoid rereading.3. Add methods on
Version
,Channel
, andDate
to query themTake the current methods that use these values, and turn them into methods on the values, so you use
Version::read
or equivalent, and then call methods to make queries for features and the like.The text was updated successfully, but these errors were encountered: