Repository navigation
Conversation
|
Looks great! I would only suggest simplifying the calculations and use of the if separator then
local group = options.group or 2
-- If exactly a multiple of group size, there will be a trailing separator
local extra = #hex % group
hex = gsub(hex, rep(".", group), "%0" .. gsub(separator, "%%", "%%%%"))
if extra == 0 then
hex = sub(hex, 1, -(#separator+1))
end
endThis is easier to read and understand for me, though I didn't see a measurable performance difference to your code. Good catch escaping the (admittedly unlikely) |
Author
|
I believe that this simplification would change group alignment of the output, which might or might not be OK. The effort to preserve the existing output faithfully is the reason why my code is unquestionably more complex. As an example, for @dmiller-nmap Opinions? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Function
tohex()instdnseis documented to support arbitrary separator for groups of hex digits. However, the actual code uses hard-coded colon as the separator, ignoring the corresponding input option. One manifestation of this gap is #2744 . This PR aligns thetohex()implementation with the documentation.As a side benefit, the function is now significantly faster, particularly with larger inputs. With the default group size of 2, the improvement is 2.6x for strings of 4 characters, 9.9x for 16, 39.3x for 64, and 122.5x for 256.
The PR will be committed after August 25, 2024, unless concerns are raised.