Skip to content

Commit

Permalink
feat(txn): delete Swap from the API. Use transaction instead
Browse files Browse the repository at this point in the history
  • Loading branch information
tigerwill90 committed Nov 17, 2024
1 parent 66f5f52 commit 4fb8fac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
13 changes: 6 additions & 7 deletions fox.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,24 +353,23 @@ func (fox *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
path = r.URL.RawPath
}

tree := fox.tree
c := tree.ctx.Get().(*cTx)
c := fox.tree.ctx.Get().(*cTx)
c.reset(w, r)

nds := *tree.root.Load()
nds := *fox.tree.root.Load()
index := findRootNode(r.Method, nds)
if index < 0 || len(nds[index].children) == 0 {
goto NoMethodFallback
}

n, tsr = tree.lookup(nds[index], r.Host, path, c, false)
n, tsr = fox.tree.lookup(nds[index], r.Host, path, c, false)
if !tsr && n != nil {
c.route = n.route
c.tsr = tsr
n.route.hall(c)
// Put back the context, if not extended more than max params or max depth, allowing
// the slice to naturally grow within the constraint.
if cap(*c.params) <= int(tree.maxParams.Load()) && cap(*c.skipNds) <= int(tree.maxDepth.Load()) {
if cap(*c.params) <= int(fox.tree.maxParams.Load()) && cap(*c.skipNds) <= int(fox.tree.maxDepth.Load()) {
c.tree.ctx.Put(c)
}
return
Expand Down Expand Up @@ -421,7 +420,7 @@ NoMethodFallback:
// Since different method and route may match (e.g. GET /foo/bar & POST /foo/{name}), we cannot set the path and params.
for i := 0; i < len(nds); i++ {
if len(nds[i].children) > 0 {
if n, tsr := tree.lookup(nds[i], r.Host, path, c, true); n != nil && (!tsr || n.route.ignoreTrailingSlash) {
if n, tsr := fox.tree.lookup(nds[i], r.Host, path, c, true); n != nil && (!tsr || n.route.ignoreTrailingSlash) {
if sb.Len() > 0 {
sb.WriteString(", ")
}
Expand All @@ -444,7 +443,7 @@ NoMethodFallback:
for i := 0; i < len(nds); i++ {
if nds[i].key != r.Method {
if len(nds[i].children) > 0 {
if n, tsr := tree.lookup(nds[i], r.Host, path, c, true); n != nil && (!tsr || n.route.ignoreTrailingSlash) {
if n, tsr := fox.tree.lookup(nds[i], r.Host, path, c, true); n != nil && (!tsr || n.route.ignoreTrailingSlash) {
if sb.Len() > 0 {
sb.WriteString(", ")
}
Expand Down
6 changes: 2 additions & 4 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -1268,11 +1268,9 @@ func (t *Tree) allocateContext() *cTx {
params: &params,
skipNds: &skipNds,
tsrParams: &tsrParams,
// This is a read only value, no reset, it's always the
// owner of the pool.
// This is a read only value, no reset
tree: t,
// This is a read only value, no reset, it's always the
// owner of the tree.
// This is a read only value, no reset
fox: t.fox,
}
}
Expand Down

0 comments on commit 4fb8fac

Please sign in to comment.