redefiniendo el builder

packs2
DEV 3 years ago
parent a6b80c0dac
commit c217571213

@ -24,7 +24,7 @@
package main
import (
"actiovething.com/go/gogo/packs/pjson"
"actiovething.com/go/gogo/packs/_pjson"
"activething.com/go/gogo/core/errs"
"activething.com/go/gogo/packs"
"fmt"
@ -32,7 +32,7 @@ import (
func main() {
p := pjson.NewBuilder(func (pk *pjson.Builder) {
p := _pjson.NewBuilder(func (pk *_pjson.Builder) {
})

@ -10,6 +10,5 @@ use (
./core/opts
./core/syncs
./packs
./packs/pjson
)

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package pjson
package _pjson
import (
"activething.com/go/gogo/core/bins"

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package pjson
package _pjson
import (
"activething.com/go/gogo/packs"

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package pjson
package _pjson
import (
"activething.com/go/gogo/packs"

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package pjson
package _pjson
import (
"activething.com/go/gogo/packs"

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package pjson
package _pjson
import "unicode/utf8"

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package pjson
package _pjson
const (
jsonCharAttUnsafe jsonCharAtt = 1 << iota

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package pjson
package _pjson

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package pjson
package _pjson
const (

@ -33,8 +33,11 @@ import (
var (
G = struct {
sentinel uint32
pool *sync.Pool
nodeSem uint32
nodePool *sync.Pool
stateSem uint32
statePool *sync.Pool
ErrInvalidNode errs.ErrCode
ErrInvalidElement errs.ErrCode

@ -1,27 +0,0 @@
// ------------------------------------------------------------------------
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name state.go
// Created by DEV
// Modified 21/01/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package jjson

@ -41,8 +41,8 @@ type (
)
func AcquireNode(parent *Node, kind NodeKind, start int) *Node {
if atomic.CompareAndSwapUint32(&G.sentinel, 0, 1) {
G.pool = &sync.Pool{
if atomic.CompareAndSwapUint32(&G.nodeSem, 0, 1) {
G.nodePool = &sync.Pool{
New: func() any {
return &Node{
Kind: NodeKindValue,
@ -51,12 +51,12 @@ func AcquireNode(parent *Node, kind NodeKind, start int) *Node {
},
}
}
return (G.pool.Get().(*Node)).Init(parent, kind, start)
return (G.nodePool.Get().(*Node)).Init(parent, kind, start)
}
func ReleaseNode(node *Node) {
if node != nil {
G.pool.Put(node.Reset())
G.nodePool.Put(node.Reset())
}
}

@ -25,11 +25,13 @@ package packs
import (
"activething.com/go/gogo/core/bins"
"sync"
"sync/atomic"
)
type (
BuilderState struct {
State struct {
/*Embedded*/*bins.Buffer
Node *Node
Error error
@ -38,15 +40,36 @@ type (
)
func NewBuilderState() *BuilderState {
return &BuilderState{
Node: AcquireNode(nil, NodeKindValue, 0),
Buffer: bins.NewBuffer(),
func AcquireState () *State {
if atomic.CompareAndSwapUint32(&G.stateSem,0,1) {
G.statePool = &sync.Pool{
New: func() any {
return &State {
Node : AcquireNode(nil, NodeKindValue, 0),
Buffer: bins.NewBuffer(),
}
},
}
}
return G.statePool.Get().(*State)
}
func ReleaseState (state *State) {
if state == nil {
return
}
state.Buffer.Reset()
state.Node.Reset()
state.Error = nil
G.statePool.Put(state)
}
func (s *BuilderState) SetError(err error) bool {
func (s *State) SetError(err error) bool {
if s.Error != nil {
return true
}
@ -59,7 +82,7 @@ func (s *BuilderState) SetError(err error) bool {
return true
}
func (s *BuilderState) SetKey(key string) bool {
func (s *State) SetKey(key string) bool {
if s.Error != nil {
return false
}
@ -71,7 +94,7 @@ func (s *BuilderState) SetKey(key string) bool {
return true
}
func (s *BuilderState) SetValue() bool {
func (s *State) SetValue() bool {
if s.Error != nil {
return false
}
@ -79,7 +102,7 @@ func (s *BuilderState) SetValue() bool {
return true
}
func (s *BuilderState) Open(kind NodeKind) bool {
func (s *State) Open(kind NodeKind) bool {
if s.Error != nil {
return false
}
@ -94,7 +117,7 @@ func (s *BuilderState) Open(kind NodeKind) bool {
return true
}
func (s *BuilderState) Close() bool {
func (s *State) Close() bool {
if s.Error != nil {
return false
}
Loading…
Cancel
Save

Powered by TurnKey Linux.