From 73140710707924e71f45204d965e1a4e514e071f Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 1 Jul 2015 11:31:10 -0700 Subject: [PATCH] User struct{} instead of bool for saving session, saves a 1byte --- cmd-cp.go | 3 ++- cmd-sync.go | 3 ++- session.go | 18 +++++++++--------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cmd-cp.go b/cmd-cp.go index 69909069..7a4bc036 100644 --- a/cmd-cp.go +++ b/cmd-cp.go @@ -115,7 +115,8 @@ func doCopySession(cURLs cpURLs, bar *barSend, s *sessionV1) error { } // store files which have finished copying - s.Files[cURLs.SourceContent.Name] = true + s.Files[cURLs.SourceContent.Name] = struct{}{} + return nil } diff --git a/cmd-sync.go b/cmd-sync.go index afe6e71d..793430f3 100644 --- a/cmd-sync.go +++ b/cmd-sync.go @@ -130,8 +130,9 @@ func doSyncSession(sURLs syncURLs, bar *barSend, syncQueue chan bool, ssCh chan } } <-syncQueue // Signal that this copy routine is done. + // store files which have finished copying - s.Files[sURLs.SourceContent.Name] = true + s.Files[sURLs.SourceContent.Name] = struct{}{} } func doPrepareSyncURLs(sourceURL string, targetURLs []string, bar barSend, lock countlock.Locker) { diff --git a/session.go b/session.go index 37029124..010b9281 100644 --- a/session.go +++ b/session.go @@ -30,13 +30,13 @@ import ( ) type sessionV1 struct { - Version string `json:"version"` - Started time.Time `json:"started"` - CommandType string `json:"command-type"` - SessionID string `json:"session-id"` - RootPath string `json:"working-directory"` - URLs []string `json:"args"` - Files map[string]bool `json:"files"` + Version string `json:"version"` + Started time.Time `json:"started"` + CommandType string `json:"command-type"` + SessionID string `json:"session-id"` + RootPath string `json:"working-directory"` + URLs []string `json:"args"` + Files map[string]struct{} `json:"files"` Lock *sync.Mutex `json:"-"` } @@ -98,7 +98,7 @@ func newSessionV1() (config quick.Config, err error) { // map of command and files copied s.URLs = nil s.Started = time.Now().UTC() - s.Files = make(map[string]bool) + s.Files = make(map[string]struct{}) s.Lock = new(sync.Mutex) s.SessionID = newSID(8) return quick.New(s) @@ -152,7 +152,7 @@ func loadSession(sid string) (*sessionV1, error) { // map of command and files copied s.URLs = nil s.Lock = new(sync.Mutex) - s.Files = make(map[string]bool) + s.Files = make(map[string]struct{}) qs, err := quick.New(s) if err != nil { return nil, iodine.New(err, nil)