Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions watcher_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ func BenchmarkAddRemove(b *testing.B) {
b.Cleanup(func() { _ = w.Close() })

b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
if err := w.Add(dir, All); err != nil {
b.Fatalf("Add: %v", err)
}
Expand Down Expand Up @@ -55,9 +54,8 @@ func BenchmarkEventThroughput(b *testing.B) {
}()

b.ReportAllocs()
b.ResetTimer()
payload := []byte("x")
for i := 0; i < b.N; i++ {
for b.Loop() {
if err := os.WriteFile(target, payload, 0o644); err != nil {
b.Fatalf("WriteFile: %v", err)
}
Expand All @@ -77,8 +75,7 @@ func BenchmarkAddRecursive(b *testing.B) {
buildFlatTree(b, root, dirs)

b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
w, err := NewWatcher()
if err != nil {
b.Fatalf("NewWatcher: %v", err)
Expand All @@ -97,7 +94,7 @@ func BenchmarkAddRecursive(b *testing.B) {
// counts while still exercising the walk + register cost.
func buildFlatTree(tb testing.TB, root string, n int) {
tb.Helper()
for i := 0; i < n; i++ {
for i := range n {
if err := os.Mkdir(filepath.Join(root, "d"+strconv.Itoa(i)), 0o755); err != nil {
tb.Fatalf("Mkdir: %v", err)
}
Expand Down
8 changes: 3 additions & 5 deletions watcher_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ func handleFSEventsCallback(clientInfo uintptr, n int, pathsPtr, flagsPtr unsafe

ptrSize := unsafe.Sizeof(uintptr(0))

for i := 0; i < n; i++ {
for i := range n {
// Read char* from the paths array (char**) without uintptr→unsafe.Pointer.
cStr := *(*unsafe.Pointer)(unsafe.Add(pathsPtr, uintptr(i)*ptrSize))
p := goString(cStr)
Expand All @@ -460,11 +460,9 @@ func handleFSEventsCallback(clientInfo uintptr, n int, pathsPtr, flagsPtr unsafe
key := pathKey(r.path)
if fs, exists := w.streams[key]; exists {
delete(w.streams, key)
w.cleanupW.Add(1)
go func() {
defer w.cleanupW.Done()
w.cleanupW.Go(func() {
stopStream(fs.stream)
}()
})
}
}
w.mu.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ func TestWatchDirWithSpace(t *testing.T) {
}

func TestConcurrentAddClose(t *testing.T) {
for i := 0; i < 50; i++ {
for range 50 {
w, err := NewWatcher()
if err != nil {
t.Fatalf("NewWatcher: %v", err)
Expand Down
Loading