From b4c31c4c714c557d6ecbf8004ffff44c5853b8cc Mon Sep 17 00:00:00 2001 From: Ting-Wei Lan Date: Mon, 11 Mar 2019 12:18:57 +0800 Subject: core: vm: sqlvm: schema: drop pointers from slices The number of tables, columns, indices are all limited to 256, so we don't have to do much memory copying during appending. Drop pointers from slices to save memory for storing pointers and possibly improve locality. --- core/vm/sqlvm/schema/schema.go | 6 +++--- core/vm/sqlvm/schema/schema_test.go | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'core/vm/sqlvm') diff --git a/core/vm/sqlvm/schema/schema.go b/core/vm/sqlvm/schema/schema.go index 76c843387..993843105 100644 --- a/core/vm/sqlvm/schema/schema.go +++ b/core/vm/sqlvm/schema/schema.go @@ -48,13 +48,13 @@ const ( ) // Schema defines sqlvm schema struct. -type Schema []*Table +type Schema []Table // Table defiens sqlvm table struct. type Table struct { Name []byte - Columns []*Column - Indices []*Index + Columns []Column + Indices []Index } // Index defines sqlvm index struct. diff --git a/core/vm/sqlvm/schema/schema_test.go b/core/vm/sqlvm/schema/schema_test.go index 5d252ef85..8a9044857 100644 --- a/core/vm/sqlvm/schema/schema_test.go +++ b/core/vm/sqlvm/schema/schema_test.go @@ -65,9 +65,9 @@ func (s *SchemaTestSuite) TestEncodeAndDecodeColumn() { func (s *SchemaTestSuite) TestEncodeAndDecodeSchema() { schema := Schema{ - &Table{ + Table{ Name: []byte("test"), - Columns: []*Column{ + Columns: []Column{ { column: column{ Name: []byte("a"), @@ -78,7 +78,7 @@ func (s *SchemaTestSuite) TestEncodeAndDecodeSchema() { Default: true, }, }, - Indices: []*Index{ + Indices: []Index{ { Name: []byte("idx"), Attr: IndexAttrUnique, @@ -86,7 +86,7 @@ func (s *SchemaTestSuite) TestEncodeAndDecodeSchema() { }, }, }, - &Table{ + Table{ Name: []byte("test2"), }, } @@ -111,13 +111,13 @@ func (s *SchemaTestSuite) TestEncodeAndDecodeSchema() { for j := 0; j < len(table.Columns); j++ { column := table.Columns[j] column2 := table.Columns[j] - s.Require().Equal(*column, *column2) + s.Require().Equal(column, column2) } for j := 0; j < len(table.Indices); j++ { index := table.Indices[j] index2 := table2.Indices[j] - s.Require().Equal(*index, *index2) + s.Require().Equal(index, index2) } } } -- cgit v1.2.3