Skip to content

Commit

Permalink
more pooling
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic BIDON <[email protected]>
  • Loading branch information
fredbi committed Jan 11, 2024
1 parent d8542b1 commit b5f844b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
5 changes: 4 additions & 1 deletion info.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ func (v VendorExtensible) MarshalJSON() ([]byte, error) {

// UnmarshalJSON for this extensible object
func (v *VendorExtensible) UnmarshalJSON(data []byte) error {
var d map[string]interface{}
d := poolOfMaps.BorrowMap()
defer func() {
poolOfMaps.RedeemMap(d)
}()
if err := json.Unmarshal(data, &d); err != nil {
return err
}
Expand Down
9 changes: 6 additions & 3 deletions ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ func (r Ref) MarshalJSON() ([]byte, error) {

// UnmarshalJSON unmarshals this ref from a JSON object
func (r *Ref) UnmarshalJSON(d []byte) error {
var v map[string]interface{}
v := poolOfMaps.BorrowMap()
defer func() {
poolOfMaps.RedeemMap(v)
}()
if err := json.Unmarshal(d, &v); err != nil {
return err
}
Expand All @@ -154,7 +157,7 @@ func (r *Ref) UnmarshalJSON(d []byte) error {

// GobEncode provides a safe gob encoder for Ref
func (r Ref) GobEncode() ([]byte, error) {
var b bytes.Buffer
var b bytes.Buffer // TODO: grow
raw, err := r.MarshalJSON()
if err != nil {
return nil, err
Expand All @@ -165,7 +168,7 @@ func (r Ref) GobEncode() ([]byte, error) {

// GobDecode provides a safe gob decoder for Ref
func (r *Ref) GobDecode(b []byte) error {
var raw []byte
var raw []byte // TODO
buf := bytes.NewBuffer(b)
err := gob.NewDecoder(buf).Decode(&raw)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type ResponsesProps struct {

// MarshalJSON marshals responses as JSON
func (r ResponsesProps) MarshalJSON() ([]byte, error) {
toser := map[string]Response{}
toser := make(map[string]Response, len(r.StatusCodeResponses)+1)
if r.Default != nil {
toser["default"] = *r.Default
}
Expand Down
1 change: 0 additions & 1 deletion schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,6 @@ func (s *Schema) UnmarshalJSON(data []byte) error {
SwaggerSchemaProps: props.SwaggerSchemaProps,
}

//var d map[string]interface{}
d := poolOfMaps.BorrowMap()
defer func() {
poolOfMaps.RedeemMap(d)
Expand Down

0 comments on commit b5f844b

Please sign in to comment.