halostatue / minitar

Minimal pure-ruby support for POSIX tar(1) archives.
Other
38 stars 27 forks source link

No unnecessary strings on POSIX header creation #19

Closed halostatue closed 7 years ago

halostatue commented 7 years ago

The POSIX header creation methods created a new 512-byte string of NULL bytes just to see if the header was an empty header. This could be simplified with a single 512-byte constant string for comparison, but a short-circuiting comparison will be more efficient over-all. Use the #each_byte enumerator with the #any? test method on #nonzero? (data.each_byte.any?(&:nonzero?)).

coveralls commented 7 years ago

Coverage Status

Coverage increased (+0.4%) to 80.043% when pulling 14d7c088199a32a38d9db3c67323d4cea3f60e6f on stop-creating-unnecessary-strings into a485f960307bbc3a2305469aece99dd73778fe72 on master.

coveralls commented 7 years ago

Coverage Status

Coverage increased (+0.6%) to 80.196% when pulling d2a025f9bccba9f02e77ccc596bb5241c2150810 on stop-creating-unnecessary-strings into a485f960307bbc3a2305469aece99dd73778fe72 on master.