-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Avoid unnecessary FooService allocations #390
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
Closed
+35
−56
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,6 +108,8 @@ type Client struct { | |
rateLimits [categories]Rate // Rate limits for the client as determined by the most recent API calls. | ||
mostRecent rateLimitCategory | ||
|
||
common service | ||
|
||
// Services used for talking to different parts of the GitHub API. | ||
Activity *ActivityService | ||
Authorizations *AuthorizationsService | ||
|
@@ -125,6 +127,10 @@ type Client struct { | |
Reactions *ReactionsService | ||
} | ||
|
||
type service struct { | ||
client *Client | ||
} | ||
|
||
// ListOptions specifies the optional parameters to various List methods that | ||
// support pagination. | ||
type ListOptions struct { | ||
|
@@ -174,20 +180,21 @@ func NewClient(httpClient *http.Client) *Client { | |
uploadURL, _ := url.Parse(uploadBaseURL) | ||
|
||
c := &Client{client: httpClient, BaseURL: baseURL, UserAgent: userAgent, UploadURL: uploadURL} | ||
c.Activity = &ActivityService{client: c} | ||
c.Authorizations = &AuthorizationsService{client: c} | ||
c.Gists = &GistsService{client: c} | ||
c.Git = &GitService{client: c} | ||
c.Gitignores = &GitignoresService{client: c} | ||
c.Issues = &IssuesService{client: c} | ||
c.Organizations = &OrganizationsService{client: c} | ||
c.PullRequests = &PullRequestsService{client: c} | ||
c.Repositories = &RepositoriesService{client: c} | ||
c.Search = &SearchService{client: c} | ||
c.Users = &UsersService{client: c} | ||
c.Licenses = &LicensesService{client: c} | ||
c.Migrations = &MigrationService{client: c} | ||
c.Reactions = &ReactionsService{client: c} | ||
c.common.client = c | ||
c.Activity = (*ActivityService)(&c.common) | ||
c.Authorizations = (*AuthorizationsService)(&c.common) | ||
c.Gists = (*GistsService)(&c.common) | ||
c.Git = (*GitService)(&c.common) | ||
c.Gitignores = (*GitignoresService)(&c.common) | ||
c.Issues = (*IssuesService)(&c.common) | ||
c.Organizations = (*OrganizationsService)(&c.common) | ||
c.PullRequests = (*PullRequestsService)(&c.common) | ||
c.Repositories = (*RepositoriesService)(&c.common) | ||
c.Search = (*SearchService)(&c.common) | ||
c.Users = (*UsersService)(&c.common) | ||
c.Licenses = (*LicensesService)(&c.common) | ||
c.Migrations = (*MigrationService)(&c.common) | ||
c.Reactions = (*ReactionsService)(&c.common) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you go ahead and sort these as well? They were always supposed to be, but it looks like the last few got added to the bottom. |
||
return c | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since this optimization is quite small and subtle, I think it'd be nice to leave a small, unobtrusive comment here.
That would reduce the chances of someone accidentally reverting this optimization a year from now, because they may not immediately understand why the code is arranged in this way instead of something simpler.
Something like:
(Or something along those lines, phrased in a better way.)
Placing it inline, on the right, is a cue to only read the comment it if you care about editing this section of code.
It's up to you, if you think it's worth it.
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.
As a side benefit, someone who cares about finding more details/context can use find this commit via git blame.
So the comment can be very short, and a more detailed explanation can go into the commit message (which will reference the issue #390).