Skip to content
This repository has been archived by the owner on Aug 14, 2020. It is now read-only.

avoid O(N) and fix defer reader close #180

Merged
merged 2 commits into from
Jul 8, 2016
Merged

avoid O(N) and fix defer reader close #180

merged 2 commits into from
Jul 8, 2016

Conversation

runcom
Copy link
Contributor

@runcom runcom commented Jul 7, 2016

  • First commit deals with an O(N) routine and removes it (the last layer ID index takes N-1 cycle to be found)
  • Second commit remove a reader close call because the reader is used after the function returns

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
@@ -512,7 +504,6 @@ func (rb *RepositoryBackend) getLayerV2(layerID string, dockerURL *types.ParsedD
if err != nil {
return nil, nil, err
}
defer res.Body.Close()
Copy link
Member

Choose a reason for hiding this comment

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

I just noticed that the original res doesn't get closed if this if block gets dropped into. Would you mind adding a res.Body.Close() around like 507 while you're here?

Copy link
Contributor Author

@runcom runcom Jul 7, 2016

Choose a reason for hiding this comment

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

there's a problem however, response body closing is an issue in all of this routine in case of any errors during the function, I'll add a defer

@cgonyeo
Copy link
Member

cgonyeo commented Jul 7, 2016

LGTM

@runcom
Copy link
Contributor Author

runcom commented Jul 7, 2016

@dgonyeo reworked the second commit so that if there's an error and the res var isn't nil then we close the body

if err != nil {
return nil, nil, err
}

defer func() {
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Just "and" those to save indentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to and

@iaguis
Copy link
Member

iaguis commented Jul 8, 2016

One nit but LGTM afterwards.

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
@iaguis
Copy link
Member

iaguis commented Jul 8, 2016

Thanks!

@iaguis iaguis merged commit 619e96c into appc:master Jul 8, 2016
@runcom runcom deleted the fixies branch July 8, 2016 09:56
@iaguis iaguis modified the milestones: v0.13.0, v0.12.1 Jul 14, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants