-
Notifications
You must be signed in to change notification settings - Fork 457
pkg/schema: create CamliType type #1356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
9152111 to
4980b00
Compare
4980b00 to
81fc3ed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a lot of string(foo) in this change, which suggests something isn't fully right yet. See comments.
cb7c2d9 to
8718005
Compare
8718005 to
222fc33
Compare
|
@bradfitz Alright, done!
|
| panic("dup blob seen") | ||
| } | ||
| bm.CamliType = c.str(bm.CamliType) | ||
| bm.CamliType = schema.CamliType((c.str(string(bm.CamliType)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really sure if that works, can you confirm?
AFAIK this does not copy?
This is c.str():
// str returns s, interned.
func (c *Corpus) str(s string) string {
if s == "" {
return ""
}
if s, ok := c.strs[s]; ok {
return s
}
if c.strs == nil {
c.strs = make(map[string]string)
}
c.strs[s] = s
return s
}EDIT: This seems to indicate that it works, interning should work just fine:
package main
import (
"fmt"
"reflect"
"strconv"
"unsafe"
)
type CamliType string
const (
Type12 CamliType = "12"
)
func stringptr(s string) uintptr {
return (*reflect.StringHeader)(unsafe.Pointer(&s)).Data
}
type stringInterner map[string]string
func (si stringInterner) Intern(s string) string {
if interned, ok := si[s]; ok {
return interned
}
si[s] = s
return s
}
func main() {
interner := stringInterner{}
s1 := interner.Intern(string(Type12))
s2 := interner.Intern(string(CamliType(strconv.Itoa(12))))
fmt.Println(stringptr(s1) == stringptr(s2))
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
converting between two string-backed types is free. they'll share the same memory.
f4fed2c to
76aeee6
Compare
Create a CamliType type in pkg/schema and use it in a couple of packages. It can be implemented in other packages as we go.
76aeee6 to
8988908
Compare
I was reading pkg/index and decided to implement @mpl's TODO: