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

Update Deflate.java #692

Merged
merged 1 commit into from
Oct 30, 2024
Merged

Update Deflate.java #692

merged 1 commit into from
Oct 30, 2024

Conversation

mjmst74
Copy link
Contributor

@mjmst74 mjmst74 commented Oct 28, 2024

Updates back to match the logic from jzlib's Deflate class to set len, minus jzlib's unnecessary cast to (int)

len = MAX_MATCH - (int)(strend - scan);

All tests are passing. I did not add a test to the codebase, but with a 105mb XML file, compression level 6

before this update:

  • time to deflate: 119.6 seconds
  • deflated size: 70mb

after this update:

  • time to deflate: 2.4 seconds
  • deflated size: 6.2mb

@@ -1309,7 +1309,7 @@ int longest_match(int cur_match) {
&& window[++scan] == window[++match] && window[++scan] == window[++match]
&& scan < strend);

len = MAX_MATCH - strend - scan;
len = MAX_MATCH - (strend - scan);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment here explaining that the parenthesis are required?
Otherwise someone may in the future believe they are unnecessary and remove them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem - I added a comment, based on my best understanding of the longest_match method.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please run mvn formatter:format so this comment is formatted correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In progress.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you pull the third line of this comment up to the second line so that it doesn't appear to awkward?
I.e.

      // len here is set to MAX_MATCH minus (strend minus scan, i.e. the distance between scan and
      // strend) to ensure that best_len is set to the best possible length to lookahead

Copy link

sonarcloud bot commented Oct 28, 2024

Copy link
Contributor

@norrisjeremy norrisjeremy left a comment

Choose a reason for hiding this comment

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

I believe this should be fine now, thanks!

@mwiede mwiede merged commit 42ab7f3 into mwiede:master Oct 30, 2024
8 checks passed
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.

3 participants