-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
chore: Simplify location uniquing #63263
Conversation
@@ -354,22 +354,12 @@ func (s *store) extractLocationsFromPosition( | |||
} | |||
} | |||
|
|||
return deduplicateLocations(locations), collections.DeduplicateBy(symbols, func(s string) string { return s }), nil |
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.
Before this, there is a call
locations = append(locations, convertSCIPRangesToLocations(ranges, locationKey.UploadID, locationKey.Path)...)
So all locations have the same UploadID
and Path
.
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.
LGTM, some nits
@@ -354,22 +354,12 @@ func (s *store) extractLocationsFromPosition( | |||
} | |||
} | |||
|
|||
return deduplicateLocations(locations), collections.DeduplicateBy(symbols, func(s string) string { return s }), nil | |||
// We only need to unique by the range, since all location objects share the same path and uploadID. |
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.
// We only need to unique by the range, since all location objects share the same path and uploadID. | |
// We only need to deduplicate by range, since all location objects share the same path and uploadID. |
seen.Add(x) | ||
filtered = append(filtered, x) | ||
} | ||
return filtered |
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.
Should probably call slices.Clip
on the result
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.
For defensiveness in the case of aliasing? Clipping the result will trigger a copy on future appends.
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.
Yeah that was my thinking. Honestly slices terrify me...
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.
If you want to be actually defensive in the case of aliasing, you'd have to construct a copy, and we don't want to do that here. I don't think it's worth taking half-measures like this.
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.
some nits (sorry for the noise, didn't see the automerge)
The code earlier constructing the locations attaches the same
uploadID and path to all of them, so trying to use those while
uniquing is wasteful. Let's stop doing that.
Test plan
Covered by existing tests
Changelog