-
-
Notifications
You must be signed in to change notification settings - Fork 529
Avoid duplicate keyword search #1066
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 duplicate keyword search #1066
Conversation
Sounds very cool.. |
@@ -1721,7 +1721,7 @@ func buffer(c context.Context, rd io.Reader) (buf []byte, endInd int, streamInd | |||
growSize = min(growSize*2, maximumBufSize) | |||
line := string(buf) | |||
|
|||
endInd, streamInd, err = model.DetectKeywords(line) | |||
endInd, streamInd, err = model.DetectKeywordsWithContext(c, line) |
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.
Why don't we leave the original method name DetectKeywords and pass in as 2nd parm the context from the caller. does that make any sense?
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.
There is a(n old) bug in posFloor:
if pos1 < pos2 {
return pos2
}
should be
if pos1 < pos2 {
return pos1
}
Happy to merge if you can take care of these 2 issues. |
@fancycode ping |
1d7b124
to
d94329a
Compare
Fixes #1057
The example file contains a huge object with this content:
This blows up the parsing code in
pdfcpu/pkg/pdfcpu/model/parse.go
Line 1243 in 4e0e0db
Here the keywords are searched lots of times after the start is advanced for each string literal inside the array (e.g.
(node00000002)
, etc.).The PR fixes this by searching only once for the keywords and then adjusting the position if strings / comments are found before them. In my tests the example file now parses in about 3 seconds.