Skip to content

Commit

Permalink
combine param types and replace if-else with switch
Browse files Browse the repository at this point in the history
  • Loading branch information
quasilyte authored and LK4D4 committed Jul 17, 2018
1 parent 1fc68ee commit 81cb891
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
13 changes: 7 additions & 6 deletions build/build.go
Expand Up @@ -387,7 +387,7 @@ func nameExt(name string) string {
// If an error occurs, Import returns a non-nil error and a non-nil
// *Package containing partial information.
//
func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Package, error) {
func (ctxt *Context) Import(path, srcDir string, mode ImportMode) (*Package, error) {
p := &Package{
ImportPath: path,
}
Expand Down Expand Up @@ -760,18 +760,19 @@ Found:
}
}
}
if isCgo {
switch {
case isCgo:
allTags["cgo"] = true
if ctxt.CgoEnabled {
p.CgoFiles = append(p.CgoFiles, name)
} else {
p.IgnoredGoFiles = append(p.IgnoredGoFiles, name)
}
} else if isXTest {
case isXTest:
p.XTestGoFiles = append(p.XTestGoFiles, name)
} else if isTest {
case isTest:
p.TestGoFiles = append(p.TestGoFiles, name)
} else {
default:
p.GoFiles = append(p.GoFiles, name)
}
}
Expand Down Expand Up @@ -1193,7 +1194,7 @@ func (ctxt *Context) saveCgo(filename string, di *Package, cg *ast.CommentGroup)

// expandSrcDir expands any occurrence of ${SRCDIR}, making sure
// the result is safe for the shell.
func expandSrcDir(str string, srcdir string) (string, bool) {
func expandSrcDir(str, srcdir string) (string, bool) {
// "\" delimited paths cause safeCgoName to fail
// so convert native paths with a different delimiter
// to "/" before starting (eg: on windows).
Expand Down
8 changes: 4 additions & 4 deletions build/read.go
Expand Up @@ -84,20 +84,20 @@ func (r *importReader) peekByte(skipSpace bool) byte {
continue

case '/':
c = r.readByte()
if c == '/' {
switch c = r.readByte(); c {
case '/':
for c != '\n' && r.err == nil && !r.eof {
c = r.readByte()
}
} else if c == '*' {
case '*':
var c1 byte
for (c != '*' || c1 != '/') && r.err == nil {
if r.eof {
r.syntaxError()
}
c, c1 = c1, r.readByte()
}
} else {
default:
r.syntaxError()
}
c = r.readByte()
Expand Down
8 changes: 4 additions & 4 deletions godl/vcs.go
Expand Up @@ -288,24 +288,24 @@ func (v *vcsCmd) String() string {
// If an error occurs, run prints the command line and the
// command's combined stdout+stderr to standard error.
// Otherwise run discards the command's output.
func (v *vcsCmd) run(dir string, cmd string, keyval ...string) error {
func (v *vcsCmd) run(dir, cmd string, keyval ...string) error {
_, err := v.run1(dir, cmd, keyval, true)
return err
}

// runVerboseOnly is like run but only generates error output to standard error in verbose mode.
func (v *vcsCmd) runVerboseOnly(dir string, cmd string, keyval ...string) error {
func (v *vcsCmd) runVerboseOnly(dir, cmd string, keyval ...string) error {
_, err := v.run1(dir, cmd, keyval, false)
return err
}

// runOutput is like run but returns the output of the command.
func (v *vcsCmd) runOutput(dir string, cmd string, keyval ...string) ([]byte, error) {
func (v *vcsCmd) runOutput(dir, cmd string, keyval ...string) ([]byte, error) {
return v.run1(dir, cmd, keyval, true)
}

// run1 is the generalized implementation of run and runOutput.
func (v *vcsCmd) run1(dir string, cmdline string, keyval []string, verbose bool) ([]byte, error) {
func (v *vcsCmd) run1(dir, cmdline string, keyval []string, verbose bool) ([]byte, error) {
m := make(map[string]string)
for i := 0; i < len(keyval); i += 2 {
m[keyval[i]] = keyval[i+1]
Expand Down

0 comments on commit 81cb891

Please sign in to comment.