diff options
| author | Shulhan <ms@kilabit.info> | 2021-12-26 02:02:25 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2021-12-26 02:02:25 +0700 |
| commit | a5f4a408cc7822c44f1cb54b4082469ebefe1b23 (patch) | |
| tree | 4af471499a63c90f67d6920abef9416d9f9088f8 | |
| parent | d7f415e3d9fff5ba6427294b6d6ba8e555056b76 (diff) | |
| download | pakakeh.go-a5f4a408cc7822c44f1cb54b4082469ebefe1b23.tar.xz | |
lib/io: realign all structs
The struct realign, save the occupied of struct size in the memory,
* DirWatcher: from 184 to 144 bytes (-40 bytes)
* Reader: from 16 to 8 bytes (-8 bytes)
* Watcher: from 32 to 24 bytes (-8 bytes)
| -rw-r--r-- | lib/io/dirwatcher.go | 28 | ||||
| -rw-r--r-- | lib/io/dirwatcher_test.go | 2 | ||||
| -rw-r--r-- | lib/io/reader.go | 2 | ||||
| -rw-r--r-- | lib/io/watcher.go | 14 |
4 files changed, 23 insertions, 23 deletions
diff --git a/lib/io/dirwatcher.go b/lib/io/dirwatcher.go index 857fde89..0d7e7310 100644 --- a/lib/io/dirwatcher.go +++ b/lib/io/dirwatcher.go @@ -18,6 +18,20 @@ import ( // DirWatcher is a naive implementation of directory change notification. // type DirWatcher struct { + root *memfs.Node + fs *memfs.MemFS + ticker *time.Ticker + + // Callback define a function that will be called when change detected + // on directory. + Callback WatchCallback + + // dirs contains list of directory and their sub-directories that is + // being watched for changes. + // The map key is relative path to directory and its value is a node + // information. + dirs map[string]*memfs.Node + // This struct embed memfs.Options to map the directory to be watched // into memory. // @@ -35,20 +49,6 @@ type DirWatcher struct { // This field is optional, minimum is 100 milli second and default is // 5 seconds. Delay time.Duration - - // Callback define a function that will be called when change detected - // on directory. - Callback WatchCallback - - // dirs contains list of directory and their sub-directories that is - // being watched for changes. - // The map key is relative path to directory and its value is a node - // information. - dirs map[string]*memfs.Node - - root *memfs.Node - fs *memfs.MemFS - ticker *time.Ticker } // diff --git a/lib/io/dirwatcher_test.go b/lib/io/dirwatcher_test.go index 9df6dcec..a9c14018 100644 --- a/lib/io/dirwatcher_test.go +++ b/lib/io/dirwatcher_test.go @@ -32,8 +32,8 @@ func TestDirWatcher(t *testing.T) { fmt.Printf(">>> Watching directory %q for changes ...\n", dir) exps := []struct { - state FileState path string + state FileState }{{ state: FileStateDeleted, path: "/", diff --git a/lib/io/reader.go b/lib/io/reader.go index 034bf366..a3f8319a 100644 --- a/lib/io/reader.go +++ b/lib/io/reader.go @@ -24,8 +24,8 @@ import ( // r.X // type Reader struct { - X int // X contains the current index of readed buffer. V []byte // V contains the buffer. + X int // X contains the current index of readed buffer. } // diff --git a/lib/io/watcher.go b/lib/io/watcher.go index 52db7b23..f4c2e2e7 100644 --- a/lib/io/watcher.go +++ b/lib/io/watcher.go @@ -19,18 +19,18 @@ import ( // Watcher is a naive implementation of file event change notification. // type Watcher struct { - // Delay define a duration when the new changes will be fetched from - // system. - // This field is optional, minimum is 100 millisecond and default is - // 5 seconds. - delay time.Duration + node *memfs.Node + ticker *time.Ticker // cb define a function that will be called when file modified or // deleted. cb WatchCallback - ticker *time.Ticker - node *memfs.Node + // Delay define a duration when the new changes will be fetched from + // system. + // This field is optional, minimum is 100 millisecond and default is + // 5 seconds. + delay time.Duration } // |
