From ad38d93dbc3713abbff8db692350a838d64ef3e5 Mon Sep 17 00:00:00 2001 From: 72 <72sevenzy2@gmail.com> Date: Tue, 28 Apr 2026 09:17:13 +0500 Subject: [PATCH] refactor: create seperate function to handle empty tree condition --- tree.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tree.go b/tree.go index 580abbaf..624f50d1 100644 --- a/tree.go +++ b/tree.go @@ -130,18 +130,28 @@ func (n *node) incrementChildPrio(pos int) int { return newPos } +func (n *node) compareEmptyTree(path string, fullPath string, handlers HandlersChain) { + if len(n.path) == 0 && len(n.children) == 0 { + n.insertChild(path, fullPath, handlers) + n.nType = root + return + } +} + // addRoute adds a node with the given handle to the path. // Not concurrency-safe! func (n *node) addRoute(path string, handlers HandlersChain) { fullPath := path n.priority++ - // Empty tree - if len(n.path) == 0 && len(n.children) == 0 { - n.insertChild(path, fullPath, handlers) - n.nType = root - return - } + // // Empty tree + // if len(n.path) == 0 && len(n.children) == 0 { + // n.insertChild(path, fullPath, handlers) + // n.nType = root + // return + // } + + n.compareEmptyTree(path, fullPath, handlers) parentFullPathIndex := 0