fieldalignment of all structs to save memory

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-03-06 19:45:13 +03:00
parent cb70dfa664
commit bbbcb22565
65 changed files with 667 additions and 671 deletions

View File

@@ -11,17 +11,16 @@ import (
// CertOptions are passed to cert options
type CertOptions struct {
IsCA bool
NotAfter time.Time
NotBefore time.Time
Parent *x509.Certificate
SerialNumber *big.Int
Subject pkix.Name
DNSNames []string
IPAddresses []net.IP
SerialNumber *big.Int
NotBefore time.Time
NotAfter time.Time
Parent *x509.Certificate
Pub ed25519.PublicKey
Priv ed25519.PrivateKey
Pub ed25519.PublicKey
Priv ed25519.PrivateKey
IsCA bool
}
// CertOption sets CertOptions

View File

@@ -10,18 +10,17 @@ import (
)
type pool struct {
size int
ttl time.Duration
tr transport.Transport
sync.Mutex
tr transport.Transport
conns map[string][]*poolConn
size int
ttl time.Duration
sync.Mutex
}
type poolConn struct {
transport.Client
id string
created time.Time
transport.Client
id string
}
func newPool(options Options) *pool {

View File

@@ -10,11 +10,10 @@ import (
// Buffer is ring buffer
type Buffer struct {
size int
sync.RWMutex
vals []*Entry
streams map[string]*Stream
vals []*Entry
size int
sync.RWMutex
}
// Entry is ring buffer data entry
@@ -25,12 +24,12 @@ type Entry struct {
// Stream is used to stream the buffer
type Stream struct {
// Id of the stream
Id string
// Buffered entries
Entries chan *Entry
// Stop channel
Stop chan bool
// Id of the stream
Id string
}
// Put adds a new value to ring buffer

View File

@@ -8,18 +8,18 @@ const (
// Template is a compiled representation of path templates.
type Template struct {
// Version is the version number of the format.
Version int
// OpCodes is a sequence of operations.
// Verb is a VERB part in the template
Verb string
// Original template (example: /v1/a_bit_of_everything)
Template string
// OpCodes is a sequence of operations
OpCodes []int
// Pool is a constant pool
Pool []string
// Verb is a VERB part in the template.
Verb string
// Fields is a list of field paths bound in this template.
// Fields is a list of field paths bound in this template
Fields []string
// Original template (example: /v1/a_bit_of_everything)
Template string
// Version is the version number of the format
Version int
}
// Compiler compiles utilities representation of path templates into marshallable operations.
@@ -29,14 +29,8 @@ type Compiler interface {
}
type op struct {
// code is the opcode of the operation
code OpCode
// str is a string operand of the code.
// operand is ignored if str is not empty.
str string
// operand is a numeric operand of the code.
str string
code OpCode
operand int
}

View File

@@ -6,8 +6,8 @@ import (
)
type apiRouter struct {
routes []router.Route
router.Router
routes []router.Route
}
func (r *apiRouter) Lookup(...router.QueryOption) ([]router.Route, error) {

View File

@@ -25,9 +25,10 @@ type rop struct {
// Pattern is a template pattern of http request paths defined in github.com/googleapis/googleapis/google/api/http.proto.
type Pattern struct {
verb string
// ops is a list of operations
ops []rop
// pool is a constant pool indexed by the operands or vars.
// pool is a constant pool indexed by the operands or vars
pool []string
// vars is a list of variables names to be bound by this pattern
vars []string
@@ -35,8 +36,6 @@ type Pattern struct {
stacksize int
// tailLen is the length of the fixed-size segments after a deep wildcard
tailLen int
// verb is the VERB part of the path pattern. It is empty if the pattern does not have VERB part.
verb string
// assumeColonVerb indicates whether a path suffix after a final
// colon may only be interpreted as a verb.
assumeColonVerb bool

View File

@@ -8,9 +8,9 @@ import (
)
type template struct {
segments []segment
verb string
template string
segments []segment
}
type segment interface {

View File

@@ -6,8 +6,8 @@ import (
// Pool holds the socket pool
type Pool struct {
sync.RWMutex
pool map[string]*Socket
sync.RWMutex
}
// Get socket from pool

View File

@@ -9,17 +9,12 @@ import (
// Socket is our pseudo socket for transport.Socket
type Socket struct {
id string
// closed
closed chan bool
// remote addr
send chan *transport.Message
recv chan *transport.Message
id string
remote string
// local addr
local string
// send chan
send chan *transport.Message
// recv chan
recv chan *transport.Message
local string
}
// SetLocal sets the local addr

View File

@@ -21,10 +21,9 @@ type Stream interface {
type stream struct {
Stream
sync.RWMutex
err error
request *request
sync.RWMutex
}
type request struct {

View File

@@ -21,9 +21,9 @@ type Sync interface {
type syncStore struct {
storeOpts store.Options
syncOpts Options
pendingWrites []*deque.Deque
pendingWriteTickers []*time.Ticker
syncOpts Options
sync.RWMutex
}
@@ -123,7 +123,7 @@ func (c *syncStore) Sync() error {
}
type internalRecord struct {
expiresAt time.Time
key string
value []byte
expiresAt time.Time
}

View File

@@ -12,11 +12,10 @@ import (
// authClaims to be encoded in the JWT
type authClaims struct {
Type string `json:"type"`
Scopes []string `json:"scopes"`
Metadata metadata.Metadata `json:"metadata"`
jwt.StandardClaims
Type string `json:"type"`
Scopes []string `json:"scopes"`
}
// JWT implementation of token provider
@@ -51,7 +50,7 @@ func (j *JWT) Generate(acc *auth.Account, opts ...token.GenerateOption) (*token.
// generate the JWT
expiry := time.Now().Add(options.Expiry)
t := jwt.NewWithClaims(jwt.SigningMethodRS256, authClaims{
acc.Type, acc.Scopes, acc.Metadata, jwt.StandardClaims{
Type: acc.Type, Scopes: acc.Scopes, Metadata: acc.Metadata, StandardClaims: jwt.StandardClaims{
Subject: acc.ID,
Issuer: acc.Issuer,
ExpiresAt: expiry.Unix(),

View File

@@ -25,10 +25,10 @@ type Provider interface {
// Token holds the auth token
type Token struct {
// The actual token
Token string `json:"token"`
// Time of token creation
// Created time of token created
Created time.Time `json:"created"`
// Time of token expiry
// Expiry ime of the token
Expiry time.Time `json:"expiry"`
// Token holds the actual token
Token string `json:"token"`
}