Skip to content

Commit

Permalink
geojson: use nocopyRawMessage for feature collection unmarshal
Browse files Browse the repository at this point in the history
no speed improvement but lots of bytes saved

benchmark                             old bytes     new bytes     delta
BenchmarkFeatureUnmarshalJSON-12      941182        828250        -12.00%
  • Loading branch information
paulmach committed Jan 16, 2021
1 parent 74bdecd commit 1bf7f83
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion geojson/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (f Feature) MarshalJSON() ([]byte, error) {
// Alternately one can call json.Unmarshal(f) directly for the same result.
func UnmarshalFeature(data []byte) (*Feature, error) {
f := &Feature{}
err := json.Unmarshal(data, f)
err := f.UnmarshalJSON(data)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion geojson/feature_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (fc FeatureCollection) MarshalJSON() ([]byte, error) {
// UnmarshalJSON decodes the data into a GeoJSON feature collection.
// Extra/foreign members will be put into the `ExtraMembers` attribute.
func (fc *FeatureCollection) UnmarshalJSON(data []byte) error {
tmp := make(map[string]json.RawMessage, 4)
tmp := make(map[string]nocopyRawMessage, 4)

err := json.Unmarshal(data, &tmp)
if err != nil {
Expand Down

0 comments on commit 1bf7f83

Please sign in to comment.