Skip to content

Commit eebcad6

Browse files
committed
Apply modernize fixes.
1 parent 236f251 commit eebcad6

6 files changed

Lines changed: 19 additions & 38 deletions

File tree

leveldb/cache/cache_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,7 @@ func TestCacheMap(t *testing.T) {
153153
objects := objects[id]
154154
handles := handles[id]
155155
for job := 0; job < param.concurrent; job++ {
156-
wg.Add(1)
157-
go func() {
158-
defer wg.Done()
156+
wg.Go(func() {
159157

160158
r := rand.New(rand.NewSource(time.Now().UnixNano()))
161159
for j := len(objects) * param.repeat; j >= 0; j-- {
@@ -179,7 +177,7 @@ func TestCacheMap(t *testing.T) {
179177
h.Release()
180178
}
181179
}
182-
}()
180+
})
183181
}
184182

185183
// Randomly release handles at interval.

leveldb/db_test.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2945,11 +2945,9 @@ func TestDB_GracefulClose(t *testing.T) {
29452945
for i := range 1000000 {
29462946
if !closing && h.totalTables() > 3 {
29472947
t.Logf("close db during write, index=%d", i)
2948-
closeWait.Add(1)
2949-
go func() {
2948+
closeWait.Go(func() {
29502949
h.closeDB()
2951-
closeWait.Done()
2952-
}()
2950+
})
29532951
closing = true
29542952
}
29552953
if err := h.db.Put(fmt.Appendf(nil, "%09d", i), fmt.Appendf(nil, "VAL-%09d", i), h.wo); err != nil {
@@ -2966,11 +2964,9 @@ func TestDB_GracefulClose(t *testing.T) {
29662964
for i := 0; i < n; i++ {
29672965
if !closing && i > n/2 {
29682966
t.Logf("close db during read, index=%d", i)
2969-
closeWait.Add(1)
2970-
go func() {
2967+
closeWait.Go(func() {
29712968
h.closeDB()
2972-
closeWait.Done()
2973-
}()
2969+
})
29742970
closing = true
29752971
}
29762972
if _, err := h.db.Get(fmt.Appendf(nil, "%09d", i), h.ro); err != nil {
@@ -2990,11 +2986,9 @@ func TestDB_GracefulClose(t *testing.T) {
29902986
}
29912987
if !closing {
29922988
t.Logf("close db during iter, index=%d", i)
2993-
closeWait.Add(1)
2994-
go func() {
2989+
closeWait.Go(func() {
29952990
h.closeDB()
2996-
closeWait.Done()
2997-
}()
2991+
})
29982992
closing = true
29992993
}
30002994
time.Sleep(time.Millisecond)

leveldb/table/reader.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ func (e *ErrCorrupted) Error() string {
5050
return fmt.Sprintf("leveldb/table: corruption on %s (pos=%d): %s", e.Kind, e.Pos, e.Reason)
5151
}
5252

53-
func max(x, y int) int {
54-
if x > y {
55-
return x
56-
}
57-
return y
58-
}
59-
6053
type block struct {
6154
bpool *util.BufferPool
6255
bh blockHandle
@@ -74,10 +67,7 @@ func (b *block) seek(cmp comparer.Comparer, rstart, rlimit int, key []byte) (ind
7467
m := offset + n1 + n2
7568
return cmp.Compare(b.data[m:m+int(v1)], key) > 0
7669
}) + rstart - 1
77-
if index < rstart {
78-
// The smallest key is greater-than key sought.
79-
index = rstart
80-
}
70+
index = max(index, rstart) // if index < rstart the smallest key is greater-than key sought.
8171
offset = int(binary.LittleEndian.Uint32(b.data[b.restartsOffset+4*index:]))
8272
return
8373
}

leveldb/testutil/storage.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,12 +512,13 @@ func (s *Storage) ForceRename(oldfd, newfd storage.FileDesc) (err error) {
512512
}
513513

514514
func (s *Storage) openFiles() string {
515-
out := "Open files:"
515+
var out strings.Builder
516+
out.WriteString("Open files:")
516517
for x, writer := range s.opens {
517518
fd := unpackFile(x)
518-
out += fmt.Sprintf("\n · fd=%s writer=%v", fd, writer)
519+
out.WriteString(fmt.Sprintf("\n · fd=%s writer=%v", fd, writer))
519520
}
520-
return out
521+
return out.String()
521522
}
522523

523524
func (s *Storage) CloseCheck() {

leveldb/version_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,11 @@ func TestVersionReference(t *testing.T) {
310310
var wg sync.WaitGroup
311311
readN := rand.Intn(300)
312312
for range readN {
313-
wg.Add(1)
314-
go func() {
313+
wg.Go(func() {
315314
v := s.version()
316315
time.Sleep(time.Millisecond * time.Duration(rand.Intn(300)))
317316
v.release()
318-
wg.Done()
319-
}()
317+
})
320318
}
321319

322320
v := s.version()

manualtest/dbstress/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ var (
5252
type arrayInt []int
5353

5454
func (a arrayInt) String() string {
55-
var str string
55+
var str strings.Builder
5656
for i, n := range a {
5757
if i > 0 {
58-
str += ","
58+
str.WriteString(",")
5959
}
60-
str += strconv.Itoa(n)
60+
str.WriteString(strconv.Itoa(n))
6161
}
62-
return str
62+
return str.String()
6363
}
6464

6565
func (a *arrayInt) Set(str string) error {

0 commit comments

Comments
 (0)