diff options
| author | Shulhan <ms@kilabit.info> | 2023-09-10 23:36:27 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-09-11 02:26:33 +0700 |
| commit | 9d05da3b79182f0fa63c268cc9c028482ae6a1c9 (patch) | |
| tree | 8bd26fb347a1672f597375da4099d784770ac9a3 /lib/text | |
| parent | db97fff977fd18992bddc411b769893edb1dd86e (diff) | |
| download | pakakeh.go-9d05da3b79182f0fa63c268cc9c028482ae6a1c9.tar.xz | |
lib/text: realign struct for better size allocation
The realignment reduce the cost of the following struct,
* Chunk: from 16 to 8 bytes (-8)
* struct in TestChunk_MarshalJSON: from 40 to 32 bytes (-8)
* diff.LineChange: from 96 to 88 bytes (-8)
* Line: from 16 to 8 bytes (-8)
* struct in TestLine_MarshalJSON: from 40 to 32 bytes (-8)
Diffstat (limited to 'lib/text')
| -rw-r--r-- | lib/text/chunk.go | 2 | ||||
| -rw-r--r-- | lib/text/chunk_test.go | 2 | ||||
| -rw-r--r-- | lib/text/diff/linechange.go | 12 | ||||
| -rw-r--r-- | lib/text/line.go | 2 | ||||
| -rw-r--r-- | lib/text/line_test.go | 2 |
5 files changed, 13 insertions, 7 deletions
diff --git a/lib/text/chunk.go b/lib/text/chunk.go index ddf2edc4..9a2db9e6 100644 --- a/lib/text/chunk.go +++ b/lib/text/chunk.go @@ -13,8 +13,8 @@ import ( // Chunk represent subset of line, contain starting position and slice of // bytes in line. type Chunk struct { - StartAt int V []byte + StartAt int } // JoinChunks all chunk's values using `sep` as separator and return it as diff --git a/lib/text/chunk_test.go b/lib/text/chunk_test.go index 36f1cf8b..403d8c65 100644 --- a/lib/text/chunk_test.go +++ b/lib/text/chunk_test.go @@ -7,8 +7,8 @@ import ( func TestChunk_MarshalJSON(t *testing.T) { type testCase struct { - chunk Chunk exp string + chunk Chunk } var cases = []testCase{{ diff --git a/lib/text/diff/linechange.go b/lib/text/diff/linechange.go index 0a659f9f..b9f18470 100644 --- a/lib/text/diff/linechange.go +++ b/lib/text/diff/linechange.go @@ -13,15 +13,21 @@ import ( // LineChange represent one change in text. type LineChange struct { - Old text.Line - New text.Line Adds text.Chunks Dels text.Chunks + + Old text.Line + New text.Line } // NewLineChange create a pointer to new LineChange object. func NewLineChange(old, new text.Line) *LineChange { - return &LineChange{old, new, text.Chunks{}, text.Chunks{}} + return &LineChange{ + Adds: text.Chunks{}, + Dels: text.Chunks{}, + Old: old, + New: new, + } } // String return formatted content of LineChange. diff --git a/lib/text/line.go b/lib/text/line.go index 254fc0dc..a2cbbfee 100644 --- a/lib/text/line.go +++ b/lib/text/line.go @@ -12,8 +12,8 @@ import ( // Line represent line number and slice of bytes as string. type Line struct { - N int V []byte + N int } func (line Line) MarshalJSON() ([]byte, error) { diff --git a/lib/text/line_test.go b/lib/text/line_test.go index e4395592..dce2e040 100644 --- a/lib/text/line_test.go +++ b/lib/text/line_test.go @@ -7,8 +7,8 @@ import ( func TestLine_MarshalJSON(t *testing.T) { type testCase struct { - line Line exp string + line Line } var cases = []testCase{{ |
