tidwall cbfb271541 Updated data structures to use Go generics.
Prior to this commit all objects in the Collection data structures
were boxed in an Go interface{} which adds an extra 8 bytes per
object and requires assertion to unbox.

Go 1.18, released early 2022, introduced generics, which allows
for storing the objects without boxing. This provides a extra
boost in performance and lower in-memory footprint.
2022-09-12 09:12:51 -07:00

74 lines
1.2 KiB
Go

package collection
import (
"encoding/json"
"github.com/tidwall/geojson"
"github.com/tidwall/geojson/geometry"
)
type String string
var _ geojson.Object = String("")
func (s String) Spatial() geojson.Spatial {
return geojson.EmptySpatial{}
}
func (s String) ForEach(iter func(geom geojson.Object) bool) bool {
return iter(s)
}
func (s String) Empty() bool {
return true
}
func (s String) Valid() bool {
return false
}
func (s String) Rect() geometry.Rect {
return geometry.Rect{}
}
func (s String) Center() geometry.Point {
return geometry.Point{}
}
func (s String) AppendJSON(dst []byte) []byte {
data, _ := json.Marshal(string(s))
return append(dst, data...)
}
func (s String) String() string {
return string(s)
}
func (s String) JSON() string {
return string(s.AppendJSON(nil))
}
func (s String) MarshalJSON() ([]byte, error) {
return s.AppendJSON(nil), nil
}
func (s String) Within(obj geojson.Object) bool {
return false
}
func (s String) Contains(obj geojson.Object) bool {
return false
}
func (s String) Intersects(obj geojson.Object) bool {
return false
}
func (s String) NumPoints() int {
return 0
}
func (s String) Distance(obj geojson.Object) float64 {
return 0
}