From 4118a68e25216eefa8825f742e0f6b287d8c3ff1 Mon Sep 17 00:00:00 2001 From: Hiromu OCHIAI Date: Thu, 7 Sep 2023 15:53:44 +0900 Subject: [PATCH] Change interface name: NumOfWorkers --- README.md | 6 +++--- all_test.go | 6 +++--- benchmark_test.go | 16 ++++++++-------- copy.go | 4 ++-- options.go | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index fd8da9e..7c8b4e0 100644 --- a/README.md +++ b/README.md @@ -87,17 +87,17 @@ type Options struct { // e.g., You can use embed.FS to copy files from embedded filesystem. FS fs.FS - // NumberOfWorkers represents the number of workers used for + // NumOfWorkers represents the number of workers used for // concurrent copying contents of directories. // If 0 or 1, it does not use goroutine for copying directories. // Please refer to https://pkg.go.dev/golang.org/x/sync/semaphore for more details. - NumberOfWorkers int64 + NumOfWorkers int64 // PreferConcurrent is a function to determine whether or not // to use goroutine for copying contents of directories. // If PreferConcurrent is nil, which is default, it does concurrent // copying for all directories. - // If NumberOfWorkers is 0 or 1, this function will be ignored. + // If NumOfWorkers is 0 or 1, this function will be ignored. PreferConcurrent func(srcdir, destdir string) (bool, error) } ``` diff --git a/all_test.go b/all_test.go index 6256b0b..13bae07 100644 --- a/all_test.go +++ b/all_test.go @@ -476,14 +476,14 @@ func (r *SleepyReader) Read(p []byte) (int, error) { return n, e } -func TestOptions_NumberOfWorkers(t *testing.T) { - opt := Options{NumberOfWorkers: 3} +func TestOptions_NumOfWorkers(t *testing.T) { + opt := Options{NumOfWorkers: 3} err := Copy("test/data/case19", "test/data.copy/case19", opt) Expect(t, err).ToBe(nil) } func TestOptions_PreferConcurrent(t *testing.T) { - opt := Options{NumberOfWorkers: 4, PreferConcurrent: func(sd, dd string) (bool, error) { + opt := Options{NumOfWorkers: 4, PreferConcurrent: func(sd, dd string) (bool, error) { return strings.HasSuffix(sd, "concurrent"), nil }} err := Copy("test/data/case19", "test/data.copy/case19_preferconcurrent", opt) diff --git a/benchmark_test.go b/benchmark_test.go index 0817440..3a3e153 100644 --- a/benchmark_test.go +++ b/benchmark_test.go @@ -5,33 +5,33 @@ import ( "testing" ) -func BenchmarkOptions_NumberOfWorkers_0(b *testing.B) { +func BenchmarkOptions_NumOfWorkers_0(b *testing.B) { var num int64 = 0 // 0 or 1 = single-threaded - opt := Options{NumberOfWorkers: num} + opt := Options{NumOfWorkers: num} for i := 0; i < b.N; i++ { Copy("test/data/case19", fmt.Sprintf("test/data.copy/case19-%d-%d", num, i), opt) } } -func BenchmarkOptions_NumberOfWorkers_2(b *testing.B) { +func BenchmarkOptions_NumOfWorkers_2(b *testing.B) { var num int64 = 2 - opt := Options{NumberOfWorkers: num} + opt := Options{NumOfWorkers: num} for i := 0; i < b.N; i++ { Copy("test/data/case19", fmt.Sprintf("test/data.copy/case19-%d-%d", num, i), opt) } } -func BenchmarkOptions_NumberOfWorkers_4(b *testing.B) { +func BenchmarkOptions_NumOfWorkers_4(b *testing.B) { var num int64 = 4 - opt := Options{NumberOfWorkers: num} + opt := Options{NumOfWorkers: num} for i := 0; i < b.N; i++ { Copy("test/data/case19", fmt.Sprintf("test/data.copy/case19-%d-%d", num, i), opt) } } -func BenchmarkOptions_NumberOfWorkers_8(b *testing.B) { +func BenchmarkOptions_NumOfWorkers_8(b *testing.B) { var num int64 = 8 - opt := Options{NumberOfWorkers: num} + opt := Options{NumOfWorkers: num} for i := 0; i < b.N; i++ { Copy("test/data/case19", fmt.Sprintf("test/data.copy/case19-%d-%d", num, i), opt) } diff --git a/copy.go b/copy.go index 6662f84..2979af9 100644 --- a/copy.go +++ b/copy.go @@ -22,8 +22,8 @@ type timespec struct { // Copy copies src to dest, doesn't matter if src is a directory or a file. func Copy(src, dest string, opts ...Options) error { opt := assureOptions(src, dest, opts...) - if opt.NumberOfWorkers > 1 { - opt.intent.sem = semaphore.NewWeighted(opt.NumberOfWorkers) + if opt.NumOfWorkers > 1 { + opt.intent.sem = semaphore.NewWeighted(opt.NumOfWorkers) opt.intent.ctx = context.Background() } if opt.FS != nil { diff --git a/options.go b/options.go index 978484a..1fbfcb1 100644 --- a/options.go +++ b/options.go @@ -68,17 +68,17 @@ type Options struct { // e.g., You can use embed.FS to copy files from embedded filesystem. FS fs.FS - // NumberOfWorkers represents the number of workers used for + // NumOfWorkers represents the number of workers used for // concurrent copying contents of directories. // If 0 or 1, it does not use goroutine for copying directories. // Please refer to https://pkg.go.dev/golang.org/x/sync/semaphore for more details. - NumberOfWorkers int64 + NumOfWorkers int64 // PreferConcurrent is a function to determine whether or not // to use goroutine for copying contents of directories. // If PreferConcurrent is nil, which is default, it does concurrent // copying for all directories. - // If NumberOfWorkers is 0 or 1, this function will be ignored. + // If NumOfWorkers is 0 or 1, this function will be ignored. PreferConcurrent func(srcdir, destdir string) (bool, error) // Internal use only @@ -161,7 +161,7 @@ func assureOptions(src, dest string, opts ...Options) Options { } func shouldCopyDirectoryConcurrent(opt Options, srcdir, destdir string) (bool, error) { - if opt.NumberOfWorkers <= 1 { + if opt.NumOfWorkers <= 1 { return false, nil } if opt.PreferConcurrent == nil {