-
Notifications
You must be signed in to change notification settings - Fork 160
Open
Description
Many files in this gem work heavily with recurring string literals (such as "Windows", "Android", "Mozilla", "4.0", "Opera", etc.) and other user agent fragments. Enabling # frozen_string_literal: true at the top of each Ruby file:
- Reduces string allocations by ensuring repeated literals share the same frozen object
- Guards against unintended mutations of constant strings
- Brings this gem up to modern Ruby best practices
There appear to be no code paths that depend on mutating string literals, so this change should be safe and brings potential allocation/performance improvements for free. See https://github.com/gshutler/useragent/blob/master/lib/user_agent.rb and related files for discussion of literal usage.
Proposal:
- Add
# frozen_string_literal: trueto all Ruby files inlib/(and possibly specs) - Confirm the test suite passes
- Optionally, measure object allocations with a profiler to demonstrate reduced string allocations (optional, but can be persuasive)
References: Ruby style guide on frozen string literals
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels