Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(823)

Unified Diff: service/datastore/properties.go

Issue 1620873004: Fix fast string comparison bug. (Closed) Base URL: https://github.com/luci/gae@master
Patch Set: Less test dups. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | service/datastore/properties_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/properties.go
diff --git a/service/datastore/properties.go b/service/datastore/properties.go
index e8c1813496122a0c7368038245f80931dfe2835f..b962e3ad033c901f591cce3b9bd6bee28e30dcab 100644
--- a/service/datastore/properties.go
+++ b/service/datastore/properties.go
@@ -933,11 +933,12 @@ func cmpByteSequence(a, b byteSequence) int {
}
// Byte-by-byte "slow" comparison.
- ld := a.len() - b.len()
- if ld < 0 {
- ld = -ld
+ ln := a.len()
+ if bln := b.len(); bln < ln {
+ ln = bln
}
- for i := 0; i < ld; i++ {
+
+ for i := 0; i < ln; i++ {
av, bv := a.get(i), b.get(i)
switch {
case av < bv:
@@ -947,7 +948,7 @@ func cmpByteSequence(a, b byteSequence) int {
}
}
- return ld
+ return a.len() - b.len()
}
// bytesByteSequence is a byteSequence implementation for a byte slice.
@@ -982,7 +983,7 @@ func (s stringByteSequence) fastCmp(o byteSequence) (int, bool) {
if string(s) < string(t) {
return -1, true
}
- return 0, true
+ return 1, true
}
return 0, false
}
« no previous file with comments | « no previous file | service/datastore/properties_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698