mirror of
https://github.com/minio/minio.git
synced 2025-11-07 21:02:58 -05:00
fix: minor allocation improvements in xlMetaV2 (#12133)
This commit is contained in:
@@ -524,13 +524,35 @@ func (x *xlMetaInlineData) rename(oldKey, newKey string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// remove will remove a key.
|
||||
// Returns whether the key was found.
|
||||
func (x *xlMetaInlineData) remove(key string) bool {
|
||||
// remove will remove one or more keys.
|
||||
// Returns true if any key was found.
|
||||
func (x *xlMetaInlineData) remove(keys ...string) bool {
|
||||
in := x.afterVersion()
|
||||
sz, buf, _ := msgp.ReadMapHeaderBytes(in)
|
||||
keys := make([][]byte, 0, sz)
|
||||
vals := make([][]byte, 0, sz)
|
||||
newKeys := make([][]byte, 0, sz)
|
||||
newVals := make([][]byte, 0, sz)
|
||||
var removeKey func(s []byte) bool
|
||||
|
||||
// Copy if big number of compares...
|
||||
if len(keys) > 5 && sz > 5 {
|
||||
mKeys := make(map[string]struct{}, len(keys))
|
||||
for _, key := range keys {
|
||||
mKeys[key] = struct{}{}
|
||||
}
|
||||
removeKey = func(s []byte) bool {
|
||||
_, ok := mKeys[string(s)]
|
||||
return ok
|
||||
}
|
||||
} else {
|
||||
removeKey = func(s []byte) bool {
|
||||
for _, key := range keys {
|
||||
if key == string(s) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Version plus header...
|
||||
plSize := 1 + msgp.MapHeaderSize
|
||||
@@ -546,10 +568,10 @@ func (x *xlMetaInlineData) remove(key string) bool {
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
if string(foundKey) != key {
|
||||
if !removeKey(foundKey) {
|
||||
plSize += msgp.StringPrefixSize + msgp.ArrayHeaderSize + len(foundKey) + len(foundVal)
|
||||
keys = append(keys, foundKey)
|
||||
vals = append(vals, foundVal)
|
||||
newKeys = append(newKeys, foundKey)
|
||||
newVals = append(newVals, foundVal)
|
||||
} else {
|
||||
found = true
|
||||
}
|
||||
@@ -559,13 +581,13 @@ func (x *xlMetaInlineData) remove(key string) bool {
|
||||
return false
|
||||
}
|
||||
// If none left...
|
||||
if len(keys) == 0 {
|
||||
if len(newKeys) == 0 {
|
||||
*x = nil
|
||||
return true
|
||||
}
|
||||
|
||||
// Reserialize...
|
||||
x.serialize(plSize, keys, vals)
|
||||
x.serialize(plSize, newKeys, newVals)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -891,11 +913,6 @@ func (z *xlMetaV2) AddVersion(fi FileInfo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func newXLMetaV2(fi FileInfo) (xlMetaV2, error) {
|
||||
xlMeta := xlMetaV2{}
|
||||
return xlMeta, xlMeta.AddVersion(fi)
|
||||
}
|
||||
|
||||
func (j xlMetaV2DeleteMarker) ToFileInfo(volume, path string) (FileInfo, error) {
|
||||
versionID := ""
|
||||
var uv uuid.UUID
|
||||
@@ -937,7 +954,7 @@ func (j xlMetaV2Object) ToFileInfo(volume, path string) (FileInfo, error) {
|
||||
versionID := ""
|
||||
var uv uuid.UUID
|
||||
// check if the version is not "null"
|
||||
if !bytes.Equal(j.VersionID[:], uv[:]) {
|
||||
if j.VersionID != uv {
|
||||
versionID = uuid.UUID(j.VersionID).String()
|
||||
}
|
||||
fi := FileInfo{
|
||||
@@ -1233,7 +1250,7 @@ func (z xlMetaV2) ListVersions(volume, path string) ([]FileInfo, time.Time, erro
|
||||
versions = append(versions, fi)
|
||||
}
|
||||
|
||||
sort.Sort(versionsSorter(versions))
|
||||
versionsSorter(versions).sort()
|
||||
|
||||
for i := range versions {
|
||||
versions[i].NumVersions = len(versions)
|
||||
|
||||
Reference in New Issue
Block a user