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

Refactor const.rb - freeze #3016

Merged
merged 4 commits into from Dec 24, 2022
Merged

Conversation

MSP-Greg
Copy link
Member

@MSP-Greg MSP-Greg commented Nov 7, 2022

Description

Ruby 2.3 implemented the magic comment # frozen_string_literal: true. The below shows one interesting result, join:

v1 = "Frozen?"
v2 = %w[HEAD GET POST PUT DELETE OPTIONS TRACE PATCH].freeze
v3 = v2.join ' '
v4 =  {501 => "HTTP/1.1 501 Not Implemented\r\n\r\n",
       503 => "HTTP/1.1 503 Service Unavailable\r\n\r\nBUSY"}

puts v1.frozen?      # -> true
puts v2[0].frozen?   # -> true
puts v3.frozen?      # -> false
puts v4[501].frozen? # -> true

So, remove .freeze when not needed in const.rb. Also, remove extra constants (GET POST PUT DELETE OPTIONS TRACE PATCH) that were added in 1b6b8adfaeb4.

Your checklist for this pull request

  • I have reviewed the guidelines for contributing to this repository.
  • I have added (or updated) appropriate tests if this PR fixes a bug or adds a feature.
  • My pull request is 100 lines added/removed or less so that it can be easily reviewed.
  • If this PR doesn't need tests (docs change), I added [ci skip] to the title of the PR.
  • If this closes any issues, I have added "Closes #issue" to the PR description or my commit messages.
  • I have updated the documentation accordingly.
  • All new and existing tests passed, including Rubocop.

Copy link
Member

@dentarg dentarg left a comment

Choose a reason for hiding this comment

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

Usage of ' comes from HTTP_STATUS_CODES and PUMA_SERVER_STRING, otherwise this file uses ", address that if you want or save it for later (in general I dislike doing changes like this because it makes git blame harder to use but if we are touching them anyways...)

lib/puma/const.rb Outdated Show resolved Hide resolved
lib/puma/const.rb Outdated Show resolved Hide resolved
@MSP-Greg
Copy link
Member Author

MSP-Greg commented Nov 7, 2022

@dentarg

For you, I changed all ' to " in Puma::Const. Left HTTP_STATUS_CODES (in the Puma namespace) the same.

Personally, I prefer '...

EDIT: yeah, git blame is a PITA, needing to find the commit immediately before...

@MSP-Greg
Copy link
Member Author

MSP-Greg commented Nov 7, 2022

@dentarg Thaks for the review.

I've looked at it before, but (of course) now that 6.0.0 is released, I'm really looking at it.

There are a lot of constants that could be moved, as they're only used in one file. For instance, the comment for HTTP_STATUS_CODES states "These are used so frequently that they are placed directly in Puma". Today, the only file (including tests) I find them in is request.rb. Same for some of the constant 'groups' in Puma::Const.

Any thoughts?

@dentarg
Copy link
Member

dentarg commented Nov 8, 2022

No real thoughts on that other than it sounds like a different PR :)

@MSP-Greg
Copy link
Member Author

MSP-Greg commented Nov 8, 2022

it sounds like a different PR

Of course...

@MSP-Greg
Copy link
Member Author

MSP-Greg commented Nov 8, 2022

@nateberkopec

Thoughts? Just checking, as this does remove some constants added to 6.0.0. See updated first post.

Copy link
Contributor

@francois-ferrandis francois-ferrandis left a comment

Choose a reason for hiding this comment

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

Seems like a good idea, I was wondering why all these freezes were still in place! 🙂

@nateberkopec nateberkopec merged commit 423d17c into puma:master Dec 24, 2022
@MSP-Greg MSP-Greg deleted the 00-const-freeze branch December 24, 2022 15:36
dentarg added a commit to dentarg/puma that referenced this pull request Dec 25, 2022
dentarg added a commit that referenced this pull request Dec 25, 2022
Slipped through in #3016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants