summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/util
AgeCommit message (Collapse)Author
2023-07-05Use encoding constant instead of hardcoded stringGeremia Taglialatela
Ref: https://ruby-doc.org/core-2.6.10/Encoding.html#class-Encoding-label-Changing+an+encoding
2023-07-04Merge pull request #288 from tagliala/chore/fix-non-local-exit-from-iteratorZsolt Kozaroczy
Fix Lint/NonLocalExitFromIterator offense
2023-07-02Remove conditional check for `encode` methodGeremia Taglialatela
All supported Ruby versions now support the `encode` method on strings, so the conditional check for this method has been removed. Even if the default encoding on Ruby >= 2.0 is UTF-8, this is not always the case when the `LANG` environment variable is not set to `C.UTF-8`, so the `encode` method has been preserved. Additionally, this commit updates a link to use the `https` protocol for improved security.
2023-07-01Fix Lint/NonLocalExitFromIterator offenseGeremia Taglialatela
Uses `Array#any?` instead of `Array#each`. According to benchmarks, `any?` is slightly faster when validation fails (3%) and noticeably faster when validation passes (up to 60%)
2023-06-15Fix redundant self offensesGeremia Taglialatela
No performance gain, this can be seen as a cosmetic change to have shorter lines
2023-06-13Fix safe Style/Lambda offensesGeremia Taglialatela
- Use literal syntax on single line - Use lambda method on multiple lines Ref: https://rubystyle.guide/#lambda-multi-line
2023-06-10Fix safe Style/ColonMethodCall offensesGeremia Taglialatela
Caxlsx is using both `.` and `::`, 220 occurrences vs 280 to invoke methods on `Axlsx` module. This commit standardizes the approach towards `.`, which will also allow shorter lines. Performance is not affected ``` Comparison: Axlsx.validate: 8515252.3 i/s Axlsx::validate: 8512863.7 i/s - same-ish: difference falls within error ```
2023-06-05Prefer `Kernel#format` to `String#%`Geremia Taglialatela
This commit fixes cases that cannot be detected by RuboCop Ref: https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/FormatString
2023-06-05Fix Style/FormatString offensesGeremia Taglialatela
`Kernel#format` is faster and will avoid to allocate an array compared to `String#%`. ``` IPS: kernel_format: 3877614.2 i/s string_percent: 3531475.0 i/s - 1.10x (± 0.00) slower Memory: kernel_format: 160 allocated string_percent: 200 allocated - 1.25x more ```
2023-06-05Merge pull request #274 from tagliala/chore/fix-negated-if-offensesZsolt Kozaroczy
Fix negated if offenses
2023-06-02Fix negated if offensesGeremia Taglialatela
Should also provide a negligible performance improvement, about 3% on Ruby 3.2 and 6% on Ruby 2.6 (M1 Pro)
2023-05-31Remove redundant parenthesesGeremia Taglialatela
- Style/ParenthesesAroundCondition - Style/RedundantParentheses - Style/TernaryParentheses `Style/ParenthesesAroundCondition` may be questionable, but a majority of comparison where not using parentheses, so offenses have been fixed for uniformity across the codebase
2023-05-31Use Ruby 1.9 hash syntaxGeremia Taglialatela
2023-05-31Fix Style/MutableConstant offensesGeremia Taglialatela
2023-05-31Fix string concatenation offenses in production codeGeremia Taglialatela
2023-05-31Merge pull request #259 from tagliala/chore/enable-naming-copsZsolt Kozaroczy
Enable Naming cops
2023-05-31Merge pull request #255 from pkmiec/fixSimpleTypeListRegressionZsolt Kozaroczy
Use #== and #eql? from BasicObject
2023-05-25Enable Naming copsGeremia Taglialatela
Also fix safe minor offenses - Naming/BinaryOperatorParameterName - Naming/HeredocDelimiterCase
2023-05-24Do not use collection literal in loopsGeremia Taglialatela
Also refactors Page margins to avoid code duplication
2023-05-24Merge pull request #257 from tagliala/chore/improve-cell-type-from-valueZsolt Kozaroczy
Improve cell type from value implementation
2023-05-24Merge pull request #254 from tagliala/chore/performance-redundant-block-callZsolt Kozaroczy
Fix Performance/RedundantBlockCall offense
2023-05-23Improve Regexp validatorGeremia Taglialatela
Replace `.match` with `.match?`
2023-05-22Use #== and #eql? from BasicObjectPaul Kmiec
Prior to https://github.com/caxlsx/caxlsx/pull/223, SimpleTypeList was just an object and inheritied #== / #eql? from BasicObject. These versions are fast as they just compare whether two objects sit in the same memory location. After https://github.com/caxlsx/caxlsx/pull/223, we started to inherit #== / #eql? from Array. These are slow as they crawl all the elements in the Array. This commit restores the original version of #== / #eql?.
2023-05-23Fix Performance/RedundantBlockCall offenseGeremia Taglialatela
Ref: https://github.com/fastruby/fast-ruby#proccall-and-block-arguments-vs-yieldcode
2023-05-23Enable Security copsGeremia Taglialatela
Also fixes a Security/Open offense that couldn't be exploited, because the only invocation of `get_mime_type_from_uri` was validating the input with a `URI::DEFAULT_PARSER` regexp
2023-05-22Merge pull request #244 from tagliala/chore/remove-ruby-pre-25-codeZsolt Kozaroczy
Remove check needed for Ruby < 2.5
2023-05-22Merge pull request #242 from tagliala/chore/fix-minor-safe-offensesZsolt Kozaroczy
Remove minor safe offenses
2023-05-22Merge pull request #240 from tagliala/chore/fix-void-contextsZsolt Kozaroczy
Fix Lint/Void offenses
2023-05-21Improve commentsGeremia Taglialatela
- Use https where possible - Capitalize Excel
2023-05-20Remove check needed for Ruby < 2.5Geremia Taglialatela
Ref: #202
2023-05-20Remove minor safe offensesGeremia Taglialatela
- Style/RaiseArgs - Style/RedundantCondition - Style/RedundantReturn - Style/SelfAssignment - Style/SoleNestedConditional
2023-05-20Fix Lint/Void offensesGeremia Taglialatela
Setter methods return the assigned value. Given: ```rb class MyClass def foo=(v) v = 10 42 end end ``` `my_object.foo = 5` will always return `5` This methods removes code that does not have effect
2023-05-17Merge branch 'master' into serializedAttributesZsolt Kozaroczy
2023-05-17Merge branch 'master' into chore/use-delete-prefix-suffixZsolt Kozaroczy
2023-05-17Merge branch 'master' into cacheColRefZsolt Kozaroczy
2023-05-16Replace `sub` with `delete_prefix`/`delete_suffix`Geremia Taglialatela
Ruby 2.5 introduced `delete_prefix` and `delete_suffix`. Those methods are helpful when serializing formula and array formula values, that are supposed to start and end with given prefixes Also moves formula prefix to constants so they can be used by both `Cell` and `CellSerializer` classes Formula: ``` Ruby version: 3.2.2 Comparison: delete_prefix: 8759353.5 i/s sub: 2607022.4 i/s - 3.36x (± 0.00) slower Comparison: delete_prefix: 40 allocated sub: 160 allocated - 4.00x more ``` Array Formula: ``` Ruby version: 3.2.2 Comparison: delete_prefixes: 4798837.8 i/s sub_sub: 937072.1 i/s - 5.12x (± 0.00) slower Comparison: delete_prefixes: 120 allocated sub_sub: 488 allocated - 4.07x more ```
2023-05-15Fix rubocop offensesPaul Kmiec
We still need Style/OptionalBooleanParameter as Ruby 2.7.5 gets confused with, ``` def serialized_attributes(str = +'', additional_attributes = {}, camelize_value: true) ```
2023-05-15Serialize attributes more efficientlyPaul Kmiec
The attributes in rows, cells, styles, etc are pre-defined for each type and almost never change. The current code, however, does not take that into account by reading all instance variables (via declared_attributes), filtering out the blank one and ones that are not xml attributes, and by camelizing each one. We can avoid all this extra work by computing the camels and ivars for xml attributes once and directly read the instance variables we care about.
2023-05-15Remove ability to set `u=` to true in favor of :singlePaul Kmiec
The `u=` would convert `true` to `:single` for backwards compatibility. However, it is more explicit to set it to `:single` or one of the other underline options instead of relying on the conversion.
2023-05-15Improve boolean validation constants (i.e. Axlsx::VALID_BOOLEAN_VALUES)Paul Kmiec
Added VALID_BOOLEAN_TRUE_VALUES and VALID_BOOLEAN_FALSE_VALUES so that those can be re-used in other placed and have the same notion of what a valid boolean value is. For example, we can use the true values in `Cell#u=`. Additionally, since validate_boolean / BOOLEAN_VALIDATOR are invoked so frequently, putting the likely values at the front can actually make a non-trivial difference. Since VALID_BOOLEAN_VALUES is derived from VALID_BOOLEAN_TRUE_VALUES and VALID_BOOLEAN_FALSE_VALUES, we use `Array#zip` to still end up with good order.
2023-05-15Corrected rubocop offenses in lib/axlsx.rb / test/tc_axlsx.rbPaul Kmiec
2023-05-10Fix `SimpleTypedList#to_a` and `SimpleTypedList#to_ary` returning the ↵Paul Kmiec
internal list instance The `to_a` and `to_ary` now work more like standard Array methods with `to_a` returning a new array containing the elements of self and `to_ary` returning self.
2023-05-10Derive SimpleTypedList from ArrayPaul Kmiec
Currently the SimpleTypedList is wrapping `@list` Array and re-implementing certain methods to add type / value checking and delegating all the non-destrutive methods to the internal @list. Most everything that ends up being serialized to the excel file is derived from SimpleTypedList (for example, a Row is a SimpleTypedList of Cells). This means that many of the delegated methods are hit over and over again especially `[]`. This extra delegation really adds up. We can avoid the delegation by having SimpleTypedList extend Array and still remove any un-safe methods. It is possible to re-introduce an unsafe method in a subclass of SimpleTypedList if needed. Here is one way, ```ruby class MyList < SimpleTypedList def clear @clear_method ||= Array.instance_method(:clear).bind(self) @clear_method.call end end ```
2023-05-10Move definition of valid values and validator lambdas out of the methods to ↵Koza
reduce memory consumption
2023-05-05Write directly to file io instead of buffering the output in memoryPaul Kmiec
2023-05-05Introduce BufferedZipOutputStream to avoid lots of small writes to ↵Paul Kmiec
Zip::OutputStream The BufferedZipOutputStream is a drop-in replacement for Zip::OutputStream similar to ZipCommand.
2023-05-05Pipe output directly to str and avoid additional memory allocationsPaul Kmiec
Currently, there are lots of examples of code like this, ``` str << ('<tag ' << foo << ' ' << bar << '/>') ``` which create the string for the tag in memory before piping to str. We can avoid creating all of these intermediate strings by dropping the paranthesis and piping directly to str. This relies on the `str` passed around to handle lots of small appends. This is a problem when using RubyZip, but that is solved in the next commit.
2023-05-04Fix tests / code to work with frozen string literalsPaul Kmiec
2023-05-04Enable Style/FrozenStringLiteralComment and autocorrectPaul Kmiec
2023-05-03Fix safe, minor offenses to production codeGeremia Taglialatela
- Lint/RedundantStringCoercion - Style/CommentAnnotation offenses - Style/DefWithParentheses - Style/EvalWithLocation - Style/MethodCallWithoutArgsParentheses - Style/MethodDefParentheses - Style/NilComparison - Style/Semicolon