Skip to content
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: improve GetField logic #897

Merged
merged 4 commits into from Nov 2, 2023
Merged

chore: improve GetField logic #897

merged 4 commits into from Nov 2, 2023

Conversation

jptosso
Copy link
Member

@jptosso jptosso commented Oct 31, 2023

Reduce number of allocations, loops, and complexity.

@jptosso jptosso requested a review from a team as a code owner October 31, 2023 08:55
@codecov
Copy link

codecov bot commented Oct 31, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Files Coverage Δ
internal/corazawaf/transaction.go 78.75% <100.00%> (+0.14%) ⬆️

📢 Thoughts on this report? Let us know!.

for i, c := range matches {
// in the most common scenario filteredMatches length will be
// the same as matches length, so we avoid allocating per result
filteredMatches := make([]types.MatchData, len(matches))
Copy link
Contributor

Choose a reason for hiding this comment

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

Think it's good to use make([], 0, len) and append since it basically allows Go to take care of the filteredCount variable while still preallocating

Copy link
Member Author

Choose a reason for hiding this comment

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

done!

@jcchavezs
Copy link
Member

Thanks @jptosso. Specifically this line

matches = matches[:rmi[i]-1]
does not have coverage. Do you mind adding coverage before refactoring?

@jptosso
Copy link
Member Author

jptosso commented Oct 31, 2023

Thanks @jptosso. Specifically this line

matches = matches[:rmi[i]-1]
does not have coverage. Do you mind adding coverage before refactoring?

That line was deleted

@fzipi
Copy link
Member

fzipi commented Oct 31, 2023

I like the implementation... can we find tests for the else paths?

@jptosso jptosso merged commit a0a65dd into main Nov 2, 2023
10 checks passed
@jptosso jptosso deleted the improve-getfield branch November 2, 2023 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants