diff options
| author | Shulhan <ms@kilabit.info> | 2021-12-19 02:08:27 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2021-12-19 02:13:57 +0700 |
| commit | ca89dd47d91c84e706a5a01c6f6749ddae791074 (patch) | |
| tree | 0b845c19c0214698643db56ac72037367b5a286a /lib | |
| parent | ba9c2ea6bd2a3c39f20fe7b2cc702e7fd4c99c44 (diff) | |
| download | pakakeh.go-ca89dd47d91c84e706a5a01c6f6749ddae791074.tar.xz | |
lib/memfs: realign struct Node, Options, PathNode, and on unit tests
The realign save storage spaces on struct,
* Node: from 240 to 224 bytes (-16 bytes)
* Options: from 112 to 104 bytes (-8 bytes)
* PathNode: from 16 to 8 bytes (-8 bytes)
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/memfs/memfs_test.go | 6 | ||||
| -rw-r--r-- | lib/memfs/node.go | 33 | ||||
| -rw-r--r-- | lib/memfs/node_test.go | 4 | ||||
| -rw-r--r-- | lib/memfs/options.go | 6 | ||||
| -rw-r--r-- | lib/memfs/pathnode.go | 2 |
5 files changed, 28 insertions, 23 deletions
diff --git a/lib/memfs/memfs_test.go b/lib/memfs/memfs_test.go index fb259bd3..ec5fb8b2 100644 --- a/lib/memfs/memfs_test.go +++ b/lib/memfs/memfs_test.go @@ -54,9 +54,9 @@ func TestNew(t *testing.T) { cases := []struct { desc string - opts Options expErr string expMapKeys []string + opts Options }{{ desc: "With empty dir", expErr: "open : no such file or directory", @@ -241,10 +241,10 @@ func TestMemFS_AddFile(t *testing.T) { func TestMemFS_Get(t *testing.T) { cases := []struct { + expErr error path string expV []byte expContentType []string - expErr error }{{ path: "/", }, { @@ -553,9 +553,9 @@ func TestMerge(t *testing.T) { } cases := []struct { + exp *MemFS desc string params []*MemFS - exp *MemFS }{{ desc: "with the same instance", params: []*MemFS{mfsDirect, mfsDirect}, diff --git a/lib/memfs/node.go b/lib/memfs/node.go index 4311102d..233a20d3 100644 --- a/lib/memfs/node.go +++ b/lib/memfs/node.go @@ -31,24 +31,29 @@ var ( // Node represent a single file. // type Node struct { + modTime time.Time // ModTime contains file modification time. + os.FileInfo http.File - SysPath string // The original file path in system. - Path string // Absolute file path in memory. - Content []byte // Content of file. - ContentType string // File type per MIME, for example "application/json". - Parent *Node // Pointer to parent directory. - Childs []*Node // List of files in directory. - GenFuncName string // The function name for embedded Go code. + Parent *Node // Pointer to parent directory. + + SysPath string // The original file path in system. + Path string // Absolute file path in memory. + name string // File name. + ContentType string // File type per MIME, for example "application/json". + GenFuncName string // The function name for embedded Go code. + + Childs []*Node // List of files in directory. + + Content []byte // Content of file. + plainv []byte // Content of file in plain text. + lowerv []byte // Content of file in lower cases. + + size int64 // Size of file. + off int64 // The cursor position when doing Read or Seek. - name string // File name. - modTime time.Time // ModTime contains file modification time. - mode os.FileMode // File mode. - size int64 // Size of file. - plainv []byte // Content of file in plain text. - lowerv []byte // Content of file in lower cases. - off int64 // The cursor position when doing Read or Seek. + mode os.FileMode // File mode. } // diff --git a/lib/memfs/node_test.go b/lib/memfs/node_test.go index 0a625d03..5f1d703b 100644 --- a/lib/memfs/node_test.go +++ b/lib/memfs/node_test.go @@ -24,10 +24,10 @@ func TestNode_Read(t *testing.T) { cases := []struct { desc string + expError string p []byte exp []byte expN int - expError string }{{ desc: "With empty p", }, { @@ -176,11 +176,11 @@ func TestNode_Seek(t *testing.T) { } cases := []struct { + expError error desc string offset int64 whence int exp int64 - expError error }{{ desc: "With invalid whence", offset: 5, diff --git a/lib/memfs/options.go b/lib/memfs/options.go index eeca7f2e..f85bbf8c 100644 --- a/lib/memfs/options.go +++ b/lib/memfs/options.go @@ -9,6 +9,9 @@ const ( ) type Options struct { + // EmbedOptions for GoEmbed. + Embed EmbedOptions + // Root contains path to directory where its contents will be mapped // to memory. Root string @@ -24,9 +27,6 @@ type Options struct { // memory, the MemFS will behave as directory tree. MaxFileSize int64 - // EmbedOptions for GoEmbed. - Embed EmbedOptions - // Development define a flag to bypass file in memory. // If its true, any call to Get will result in direct read to file // system. diff --git a/lib/memfs/pathnode.go b/lib/memfs/pathnode.go index f702c01a..df7d6c0f 100644 --- a/lib/memfs/pathnode.go +++ b/lib/memfs/pathnode.go @@ -15,8 +15,8 @@ import ( // PathNode contains a mapping between path and Node. // type PathNode struct { - mu sync.Mutex v map[string]*Node + mu sync.Mutex } // |
