commit 6791fa78b62100d2477e904f0c6d9002b3a1d961
parent 8fe6e6254b377abbf4d8fb4be9b43b56da21e204
Author: Matsuda Kenji <info@mtkn.jp>
Date: Sat, 21 Oct 2023 08:27:35 +0900
move tagPool.nextTag() into tagPool.add()
Diffstat:
| M | req.go | | | 19 | +++++++------------ |
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/req.go b/req.go
@@ -101,26 +101,21 @@ func newTagPool() *tagPool {
}
}
-func (tp *tagPool) nextTag() (uint16, error) {
- // TODO: optimize
+func (tp *tagPool) add() (uint16, error) {
tp.lock.Lock()
defer tp.lock.Unlock()
+ tag := NOTAG
for i := uint16(0); i < i+1; i++ {
if _, ok := tp.m[i]; !ok {
- return i, nil
+ tag = i
+ break
}
}
- return 0, fmt.Errorf("run out of tag")
-}
-
-func (tp *tagPool) add(tag uint16) error {
- tp.lock.Lock()
- defer tp.lock.Unlock()
- if _, ok := tp.m[tag]; ok {
- return fmt.Errorf("duplicate tag")
+ if tag == NOTAG {
+ return NOTAG, fmt.Errorf("run out of tag")
}
tp.m[tag] = true
- return nil
+ return tag, nil
}
func (tp *tagPool) lookup(tag uint16) bool {