@@ -102,7 +102,6 @@ func (t *trieNode) add(key, val string, priority int, r *genericReplacer) {
102
102
return
103
103
}
104
104
105
- //nolint:nestif // TODO(ldez) must be fixed.
106
105
if t .prefix != "" {
107
106
// Need to split the prefix among multiple nodes.
108
107
var n int // length of the longest common prefix
@@ -111,9 +110,10 @@ func (t *trieNode) add(key, val string, priority int, r *genericReplacer) {
111
110
break
112
111
}
113
112
}
114
- if n == len (t .prefix ) {
113
+ switch n {
114
+ case len (t .prefix ):
115
115
t .next .add (key [n :], val , priority , r )
116
- } else if n == 0 {
116
+ case 0 :
117
117
// First byte differs, start a new lookup table here. Looking up
118
118
// what is currently t.prefix[0] will lead to prefixNode, and
119
119
// looking up key[0] will lead to keyNode.
@@ -133,7 +133,7 @@ func (t *trieNode) add(key, val string, priority int, r *genericReplacer) {
133
133
t .prefix = ""
134
134
t .next = nil
135
135
keyNode .add (key [1 :], val , priority , r )
136
- } else {
136
+ default :
137
137
// Insert new node after the common section of the prefix.
138
138
next := & trieNode {
139
139
prefix : t .prefix [n :],
@@ -143,18 +143,22 @@ func (t *trieNode) add(key, val string, priority int, r *genericReplacer) {
143
143
t .next = next
144
144
next .add (key [n :], val , priority , r )
145
145
}
146
- } else if t .table != nil {
146
+ return
147
+ }
148
+
149
+ if t .table != nil {
147
150
// Insert into existing table.
148
151
m := r .mapping [key [0 ]]
149
152
if t .table [m ] == nil {
150
153
t .table [m ] = new (trieNode )
151
154
}
152
155
t .table [m ].add (key [1 :], val , priority , r )
153
- } else {
154
- t .prefix = key
155
- t .next = new (trieNode )
156
- t .next .add ("" , val , priority , r )
156
+ return
157
157
}
158
+
159
+ t .prefix = key
160
+ t .next = new (trieNode )
161
+ t .next .add ("" , val , priority , r )
158
162
}
159
163
160
164
// genericReplacer is the fully generic algorithm.
0 commit comments