@@ -33,7 +33,9 @@ function DecoratorSize:new(opts)
3333 o .column_width = opts .renderer .size .column_width
3434 o .show_folder_size = opts .renderer .size .show_folder_size
3535 o .units = { " B" , " KB" , " MB" , " GB" , " TB" , " PB" , " EB" , " ZB" , " YB" }
36- o .format_unit = opts .renderer .size .format_unit -- guaranteed to be a function
36+
37+ -- Guaranteed to be a function from previous setup
38+ o .format_unit = opts .renderer .size .format_unit
3739 o .format_size = function (size )
3840 local formatted = string
3941 .format (" %.2f" , size )
5153--- @private
5254--- @param size number size in bytes
5355--- @return string
54- --- edit: Since then I've moved a lot of ifs around getting down to only three, but I'll keep the comment just in case.
56+ --- edit: Since then I've moved a lot of ifs around getting down to only three, but I'll keep the comment bellow just in case.
5557--- NOTE: This function still try it's best to minified the string
56- --- generated, but this implies that we have more than 3 branchs
58+ --- generated, but this implies that we have some branches
5759--- to determined how much bytes can we shave from the string to
58- --- comply to self.column_width. Since we know self.column_width doesn't
59- --- change, a better way could be to decide a version of 'human_readable_size' based
60- --- on self.column_width once at this object's construction.
61- --- Basically, instead of this method, we would baking all ifs first to decide which function to bind to possible field `self.human_readable_size`
62- --- I don't actually know if it would be faster without test.
60+ --- comply to `self.column_width`.
61+ --- Since we know `self.column_width` doesn't change, a better way could be
62+ --- decide a version of 'human_readable_size' a priori, based
63+ --- on `self.column_width` *once* at this object's construction.
64+ --- Basically, instead of this method, we would "baking" all ifs first
65+ --- to decide which function to bind to possible field `self.human_readable_size`.
6366function DecoratorSize :human_readable_size (size )
6467 -- Check for nan, negative, etc.
6568 if type (size ) ~= " number" or size ~= size or size < 0 then
0 commit comments