clsx-ruby 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/clsx/helper.rb +38 -7
- data/lib/clsx/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 49ae33f9c65cab86b628e1ed9cb764242f13397135caafa48a9a431f5f3d0a78
|
|
4
|
+
data.tar.gz: a59da0c73f12ed098f411777c14986f807dccb635ea6055ecece2a08c6845f00
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5cbb6c36d0920943123f9e19c978a8ef4914669ca6b71666f770883c865ca4c2dd6d3f089ced1612d62532b881c3492df656d4381bb85533dd635c7af4009c0c
|
|
7
|
+
data.tar.gz: d6ac365bce6825166fdf51303a87398f20997075535babf65a28686dea562f46586bc0c6e9418bfac77b9307e8820b377f4b5ce2265b21d7360c405928cd524f
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v1.1.0
|
|
4
|
+
|
|
5
|
+
- Optimized hash-only path: skip dedup Hash since hash keys are unique by definition (+8%)
|
|
6
|
+
- New fast path for `clsx('base', active: cond)` string + hash pattern (+69%)
|
|
7
|
+
- Added `string + hash` benchmark scenario
|
|
8
|
+
- Use `str.dup` instead of `String.new(str)` for buffer init (+12-18% on hash paths)
|
|
9
|
+
|
|
3
10
|
## v1.0.0
|
|
4
11
|
|
|
5
12
|
- Initial release as standalone framework-agnostic gem
|
data/lib/clsx/helper.rb
CHANGED
|
@@ -49,6 +49,8 @@ module Clsx
|
|
|
49
49
|
elsif klass == Hash
|
|
50
50
|
return clsx_simple_hash(arg)
|
|
51
51
|
end
|
|
52
|
+
elsif args.size == 2
|
|
53
|
+
return clsx_string_hash(args[0], args[1]) if args[0].class == String && args[1].class == Hash # rubocop:disable Style/ClassEqualityComparison
|
|
52
54
|
end
|
|
53
55
|
|
|
54
56
|
seen = {}
|
|
@@ -61,32 +63,61 @@ module Clsx
|
|
|
61
63
|
|
|
62
64
|
private
|
|
63
65
|
|
|
66
|
+
# Hash-only path — no dedup hash needed (hash keys are unique by definition).
|
|
67
|
+
# Builds result string directly with <<.
|
|
64
68
|
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
65
69
|
def clsx_simple_hash(hash)
|
|
66
70
|
return nil if hash.empty?
|
|
67
71
|
|
|
68
|
-
|
|
72
|
+
buf = nil
|
|
69
73
|
hash.each do |key, value|
|
|
70
74
|
next unless value
|
|
71
75
|
|
|
72
76
|
klass = key.class
|
|
73
|
-
|
|
74
77
|
if klass == Symbol
|
|
75
|
-
|
|
78
|
+
str = key.name
|
|
79
|
+
buf ? (buf << ' ' << str) : (buf = str.dup)
|
|
76
80
|
elsif klass == String
|
|
77
|
-
|
|
81
|
+
next if key.empty?
|
|
82
|
+
|
|
83
|
+
buf ? (buf << ' ' << key) : (buf = key.dup)
|
|
78
84
|
else
|
|
79
|
-
# Complex key - fall back to full processing
|
|
80
85
|
seen = {}
|
|
81
86
|
clsx_process([hash], seen)
|
|
82
87
|
return seen.empty? ? nil : seen.keys.join(' ')
|
|
83
88
|
end
|
|
84
89
|
end
|
|
90
|
+
buf
|
|
91
|
+
end
|
|
92
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
85
93
|
|
|
86
|
-
|
|
94
|
+
# String + Hash fast path: clsx('base', active: cond).
|
|
95
|
+
# Builds result string directly, dedup only against base string.
|
|
96
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
97
|
+
def clsx_string_hash(str, hash)
|
|
98
|
+
return clsx_simple_hash(hash) if str.empty?
|
|
99
|
+
|
|
100
|
+
buf = str.dup
|
|
101
|
+
hash.each do |key, value|
|
|
102
|
+
next unless value
|
|
103
|
+
|
|
104
|
+
klass = key.class
|
|
105
|
+
if klass == Symbol
|
|
106
|
+
s = key.name
|
|
107
|
+
buf << ' ' << s unless s == str
|
|
108
|
+
elsif klass == String
|
|
109
|
+
buf << ' ' << key unless key.empty? || key == str
|
|
110
|
+
else
|
|
111
|
+
seen = { str => true }
|
|
112
|
+
clsx_process([hash], seen)
|
|
113
|
+
return seen.size == 1 ? str : seen.keys.join(' ')
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
buf
|
|
87
117
|
end
|
|
118
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
88
119
|
|
|
89
|
-
# rubocop:disable Style/MultipleComparison
|
|
120
|
+
# rubocop:disable Style/MultipleComparison, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
90
121
|
def clsx_process(args, seen)
|
|
91
122
|
deferred = nil
|
|
92
123
|
|
data/lib/clsx/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: clsx-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Leonid Svyatov
|
|
@@ -44,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
44
44
|
- !ruby/object:Gem::Version
|
|
45
45
|
version: '0'
|
|
46
46
|
requirements: []
|
|
47
|
-
rubygems_version: 4.0.
|
|
47
|
+
rubygems_version: 4.0.6
|
|
48
48
|
specification_version: 4
|
|
49
49
|
summary: clsx / classnames for Ruby
|
|
50
50
|
test_files: []
|