1
0
mirror of https://github.com/golang/go synced 2024-11-23 18:50:05 -07:00

all: remove some unused return parameters

As found by unparam. Picked the low-hanging fruit, consisting only of
errors that were always nil and results that were never used. Left out
those that were useful for consistency with other func signatures.

Change-Id: I06b52bbd3541f8a5d66659c909bd93cb3e172018
Reviewed-on: https://go-review.googlesource.com/102418
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Daniel Martí 2018-03-24 15:49:43 +00:00
parent b1892d740e
commit 8da180f6ca
7 changed files with 24 additions and 34 deletions

View File

@ -1070,14 +1070,14 @@ func (dec *Decoder) compileSingle(remoteId typeId, ut *userTypeInfo) (engine *de
} }
// compileIgnoreSingle compiles the decoder engine for a non-struct top-level value that will be discarded. // compileIgnoreSingle compiles the decoder engine for a non-struct top-level value that will be discarded.
func (dec *Decoder) compileIgnoreSingle(remoteId typeId) (engine *decEngine, err error) { func (dec *Decoder) compileIgnoreSingle(remoteId typeId) *decEngine {
engine = new(decEngine) engine := new(decEngine)
engine.instr = make([]decInstr, 1) // one item engine.instr = make([]decInstr, 1) // one item
op := dec.decIgnoreOpFor(remoteId, make(map[typeId]*decOp)) op := dec.decIgnoreOpFor(remoteId, make(map[typeId]*decOp))
ovfl := overflow(dec.typeString(remoteId)) ovfl := overflow(dec.typeString(remoteId))
engine.instr[0] = decInstr{*op, 0, nil, ovfl} engine.instr[0] = decInstr{*op, 0, nil, ovfl}
engine.numInstr = 1 engine.numInstr = 1
return return engine
} }
// compileDec compiles the decoder engine for a value. If the value is not a struct, // compileDec compiles the decoder engine for a value. If the value is not a struct,
@ -1168,7 +1168,7 @@ func (dec *Decoder) getIgnoreEnginePtr(wireId typeId) (enginePtr **decEngine, er
if wire != nil && wire.StructT != nil { if wire != nil && wire.StructT != nil {
*enginePtr, err = dec.compileDec(wireId, userType(emptyStructType)) *enginePtr, err = dec.compileDec(wireId, userType(emptyStructType))
} else { } else {
*enginePtr, err = dec.compileIgnoreSingle(wireId) *enginePtr = dec.compileIgnoreSingle(wireId)
} }
if err != nil { if err != nil {
delete(dec.ignorerCache, wireId) delete(dec.ignorerCache, wireId)

View File

@ -108,10 +108,7 @@ func parse(r io.Reader, bin string) (int, ParseResult, error) {
if err != nil { if err != nil {
return 0, ParseResult{}, err return 0, ParseResult{}, err
} }
events, err = removeFutile(events) events = removeFutile(events)
if err != nil {
return 0, ParseResult{}, err
}
err = postProcessTrace(ver, events) err = postProcessTrace(ver, events)
if err != nil { if err != nil {
return 0, ParseResult{}, err return 0, ParseResult{}, err
@ -505,7 +502,7 @@ func parseEvents(ver int, rawEvents []rawEvent, strings map[uint64]string) (even
// ahead and acquired the mutex before the first goroutine is scheduled, // ahead and acquired the mutex before the first goroutine is scheduled,
// so the first goroutine has to block again. Such wakeups happen on buffered // so the first goroutine has to block again. Such wakeups happen on buffered
// channels and sync.Mutex, but are generally not interesting for end user. // channels and sync.Mutex, but are generally not interesting for end user.
func removeFutile(events []*Event) ([]*Event, error) { func removeFutile(events []*Event) []*Event {
// Two non-trivial aspects: // Two non-trivial aspects:
// 1. A goroutine can be preempted during a futile wakeup and migrate to another P. // 1. A goroutine can be preempted during a futile wakeup and migrate to another P.
// We want to remove all of that. // We want to remove all of that.
@ -552,7 +549,7 @@ func removeFutile(events []*Event) ([]*Event, error) {
newEvents = append(newEvents, ev) newEvents = append(newEvents, ev)
} }
} }
return newEvents, nil return newEvents
} }
// ErrTimeOrder is returned by Parse when the trace contains // ErrTimeOrder is returned by Parse when the trace contains

View File

@ -122,15 +122,13 @@ func (p *Prog) String() string {
return b.String() return b.String()
} }
// skipNop follows any no-op or capturing instructions // skipNop follows any no-op or capturing instructions.
// and returns the resulting pc. func (p *Prog) skipNop(pc uint32) *Inst {
func (p *Prog) skipNop(pc uint32) (*Inst, uint32) {
i := &p.Inst[pc] i := &p.Inst[pc]
for i.Op == InstNop || i.Op == InstCapture { for i.Op == InstNop || i.Op == InstCapture {
pc = i.Out i = &p.Inst[i.Out]
i = &p.Inst[pc]
} }
return i, pc return i
} }
// op returns i.Op but merges all the Rune special cases into InstRune // op returns i.Op but merges all the Rune special cases into InstRune
@ -147,7 +145,7 @@ func (i *Inst) op() InstOp {
// regexp must start with. Complete is true if the prefix // regexp must start with. Complete is true if the prefix
// is the entire match. // is the entire match.
func (p *Prog) Prefix() (prefix string, complete bool) { func (p *Prog) Prefix() (prefix string, complete bool) {
i, _ := p.skipNop(uint32(p.Start)) i := p.skipNop(uint32(p.Start))
// Avoid allocation of buffer if prefix is empty. // Avoid allocation of buffer if prefix is empty.
if i.op() != InstRune || len(i.Rune) != 1 { if i.op() != InstRune || len(i.Rune) != 1 {
@ -158,7 +156,7 @@ func (p *Prog) Prefix() (prefix string, complete bool) {
var buf bytes.Buffer var buf bytes.Buffer
for i.op() == InstRune && len(i.Rune) == 1 && Flags(i.Arg)&FoldCase == 0 { for i.op() == InstRune && len(i.Rune) == 1 && Flags(i.Arg)&FoldCase == 0 {
buf.WriteRune(i.Rune[0]) buf.WriteRune(i.Rune[0])
i, _ = p.skipNop(i.Out) i = p.skipNop(i.Out)
} }
return buf.String(), i.Op == InstMatch return buf.String(), i.Op == InstMatch
} }

View File

@ -343,7 +343,7 @@ func (b *profileBuilder) addCPUData(data []uint64, tags []unsafe.Pointer) error
} }
// build completes and returns the constructed profile. // build completes and returns the constructed profile.
func (b *profileBuilder) build() error { func (b *profileBuilder) build() {
b.end = time.Now() b.end = time.Now()
b.pb.int64Opt(tagProfile_TimeNanos, b.start.UnixNano()) b.pb.int64Opt(tagProfile_TimeNanos, b.start.UnixNano())
@ -396,7 +396,6 @@ func (b *profileBuilder) build() error {
b.pb.strings(tagProfile_StringTable, b.strings) b.pb.strings(tagProfile_StringTable, b.strings)
b.zw.Write(b.pb.data) b.zw.Write(b.pb.data)
b.zw.Close() b.zw.Close()
return nil
} }
// readMapping reads /proc/self/maps and writes mappings to b.pb. // readMapping reads /proc/self/maps and writes mappings to b.pb.

View File

@ -1059,7 +1059,7 @@ func parse(layout, value string, defaultLocation, local *Location) (Time, error)
// Look for local zone with the given offset. // Look for local zone with the given offset.
// If that zone was in effect at the given time, use it. // If that zone was in effect at the given time, use it.
name, offset, _, _, _ := local.lookup(t.unixSec()) name, offset, _, _ := local.lookup(t.unixSec())
if offset == zoneOffset && (zoneName == "" || name == zoneName) { if offset == zoneOffset && (zoneName == "" || name == zoneName) {
t.setLoc(local) t.setLoc(local)
return t, nil return t, nil

View File

@ -445,7 +445,7 @@ func (t Time) abs() uint64 {
if l.cacheZone != nil && l.cacheStart <= sec && sec < l.cacheEnd { if l.cacheZone != nil && l.cacheStart <= sec && sec < l.cacheEnd {
sec += int64(l.cacheZone.offset) sec += int64(l.cacheZone.offset)
} else { } else {
_, offset, _, _, _ := l.lookup(sec) _, offset, _, _ := l.lookup(sec)
sec += int64(offset) sec += int64(offset)
} }
} }
@ -466,7 +466,7 @@ func (t Time) locabs() (name string, offset int, abs uint64) {
name = l.cacheZone.name name = l.cacheZone.name
offset = l.cacheZone.offset offset = l.cacheZone.offset
} else { } else {
name, offset, _, _, _ = l.lookup(sec) name, offset, _, _ = l.lookup(sec)
} }
sec += int64(offset) sec += int64(offset)
} else { } else {
@ -1088,7 +1088,7 @@ func (t Time) Location() *Location {
// Zone computes the time zone in effect at time t, returning the abbreviated // Zone computes the time zone in effect at time t, returning the abbreviated
// name of the zone (such as "CET") and its offset in seconds east of UTC. // name of the zone (such as "CET") and its offset in seconds east of UTC.
func (t Time) Zone() (name string, offset int) { func (t Time) Zone() (name string, offset int) {
name, offset, _, _, _ = t.loc.lookup(t.unixSec()) name, offset, _, _ = t.loc.lookup(t.unixSec())
return return
} }
@ -1181,7 +1181,7 @@ func (t *Time) UnmarshalBinary(data []byte) error {
if offset == -1*60 { if offset == -1*60 {
t.setLoc(&utcLoc) t.setLoc(&utcLoc)
} else if _, localoff, _, _, _ := Local.lookup(t.unixSec()); offset == localoff { } else if _, localoff, _, _ := Local.lookup(t.unixSec()); offset == localoff {
t.setLoc(Local) t.setLoc(Local)
} else { } else {
t.setLoc(FixedZone("", offset)) t.setLoc(FixedZone("", offset))
@ -1366,13 +1366,13 @@ func Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) T
// The lookup function expects UTC, so we pass t in the // The lookup function expects UTC, so we pass t in the
// hope that it will not be too close to a zone transition, // hope that it will not be too close to a zone transition,
// and then adjust if it is. // and then adjust if it is.
_, offset, _, start, end := loc.lookup(unix) _, offset, start, end := loc.lookup(unix)
if offset != 0 { if offset != 0 {
switch utc := unix - int64(offset); { switch utc := unix - int64(offset); {
case utc < start: case utc < start:
_, offset, _, _, _ = loc.lookup(start - 1) _, offset, _, _ = loc.lookup(start - 1)
case utc >= end: case utc >= end:
_, offset, _, _, _ = loc.lookup(end) _, offset, _, _ = loc.lookup(end)
} }
unix -= int64(offset) unix -= int64(offset)
} }

View File

@ -108,13 +108,12 @@ func FixedZone(name string, offset int) *Location {
// the start and end times bracketing sec when that zone is in effect, // the start and end times bracketing sec when that zone is in effect,
// the offset in seconds east of UTC (such as -5*60*60), and whether // the offset in seconds east of UTC (such as -5*60*60), and whether
// the daylight savings is being observed at that time. // the daylight savings is being observed at that time.
func (l *Location) lookup(sec int64) (name string, offset int, isDST bool, start, end int64) { func (l *Location) lookup(sec int64) (name string, offset int, start, end int64) {
l = l.get() l = l.get()
if len(l.zone) == 0 { if len(l.zone) == 0 {
name = "UTC" name = "UTC"
offset = 0 offset = 0
isDST = false
start = alpha start = alpha
end = omega end = omega
return return
@ -123,7 +122,6 @@ func (l *Location) lookup(sec int64) (name string, offset int, isDST bool, start
if zone := l.cacheZone; zone != nil && l.cacheStart <= sec && sec < l.cacheEnd { if zone := l.cacheZone; zone != nil && l.cacheStart <= sec && sec < l.cacheEnd {
name = zone.name name = zone.name
offset = zone.offset offset = zone.offset
isDST = zone.isDST
start = l.cacheStart start = l.cacheStart
end = l.cacheEnd end = l.cacheEnd
return return
@ -133,7 +131,6 @@ func (l *Location) lookup(sec int64) (name string, offset int, isDST bool, start
zone := &l.zone[l.lookupFirstZone()] zone := &l.zone[l.lookupFirstZone()]
name = zone.name name = zone.name
offset = zone.offset offset = zone.offset
isDST = zone.isDST
start = alpha start = alpha
if len(l.tx) > 0 { if len(l.tx) > 0 {
end = l.tx[0].when end = l.tx[0].when
@ -162,7 +159,6 @@ func (l *Location) lookup(sec int64) (name string, offset int, isDST bool, start
zone := &l.zone[tx[lo].index] zone := &l.zone[tx[lo].index]
name = zone.name name = zone.name
offset = zone.offset offset = zone.offset
isDST = zone.isDST
start = tx[lo].when start = tx[lo].when
// end = maintained during the search // end = maintained during the search
return return
@ -235,7 +231,7 @@ func (l *Location) lookupName(name string, unix int64) (offset int, ok bool) {
for i := range l.zone { for i := range l.zone {
zone := &l.zone[i] zone := &l.zone[i]
if zone.name == name { if zone.name == name {
nam, offset, _, _, _ := l.lookup(unix - int64(zone.offset)) nam, offset, _, _ := l.lookup(unix - int64(zone.offset))
if nam == zone.name { if nam == zone.name {
return offset, true return offset, true
} }