return s.s.contains(ID(int(x) - s.first))
}
-// get returns the value s maps for key x, or -1 if
-// x is not mapped or is out of range for s.
-func (s *biasedSparseMap) get(x uint) int32 {
+// get returns the value s maps for key x and true, or
+// 0/false if x is not mapped or is out of range for s.
+func (s *biasedSparseMap) get(x uint) (int32, bool) {
if s == nil || s.s == nil {
- return -1
+ return 0, false
}
if int(x) < s.first {
- return -1
+ return 0, false
}
if int(x) >= s.cap() {
- return -1
+ return 0, false
}
k := ID(int(x) - s.first)
if !s.s.contains(k) {
- return -1 // TODO: push presence check to callers?
+ return 0, false
}
return s.s.get(k)
}
// Find new homes for lost lines -- require earliest in data flow with same line that is also in same block
for i := len(order) - 1; i >= 0; i-- {
w := order[i]
- if j := pendingLines.get(w.Pos); j > -1 && f.Blocks[j] == w.Block {
+ if j, ok := pendingLines.get(w.Pos); ok && f.Blocks[j] == w.Block {
w.Pos = w.Pos.WithIsStmt()
pendingLines.remove(w.Pos)
}
ptr = la
}
}
- sr := shadowRange(shadowed.get(ptr.ID))
+ srNum, _ := shadowed.get(ptr.ID)
+ sr := shadowRange(srNum)
if sr.contains(off, off+sz) {
// Modify the store/zero into a copy of the memory state,
// effectively eliding the store operation.
// Iteration order means that first nilcheck in the chain wins, others
// are bumped into the ordinary statement preservation algorithm.
- u := b.Values[unnecessary.get(v.Args[0].ID)]
+ uid, _ := unnecessary.get(v.Args[0].ID)
+ u := b.Values[uid]
if !u.Type.IsMemory() && !u.Pos.SameFileAndLine(v.Pos) {
if u.Pos.IsStmt() == src.PosIsStmt {
pendingLines.add(u.Pos)
f.freeValue(v)
continue
}
- if v.Pos.IsStmt() != src.PosNotStmt && !notStmtBoundary(v.Op) && pendingLines.get(vl) == int32(b.ID) {
- pendingLines.remove(vl)
- v.Pos = v.Pos.WithIsStmt()
+ if v.Pos.IsStmt() != src.PosNotStmt && !notStmtBoundary(v.Op) {
+ if pl, ok := pendingLines.get(vl); ok && pl == int32(b.ID) {
+ pendingLines.remove(vl)
+ v.Pos = v.Pos.WithIsStmt()
+ }
}
if i != j {
b.Values[j] = v
}
j++
}
- if pendingLines.get(b.Pos) == int32(b.ID) {
+ if pl, ok := pendingLines.get(b.Pos); ok && pl == int32(b.ID) {
b.Pos = b.Pos.WithIsStmt()
pendingLines.remove(b.Pos)
}
// get returns the value for key k, or the zero V
// if k does not appear in the map.
-func (s *genericSparseMap[K, V]) get(k K) V {
+func (s *genericSparseMap[K, V]) get(k K) (V, bool) {
i := s.sparse[k]
if i < int32(len(s.dense)) && s.dense[i].key == k {
- return s.dense[i].val
+ return s.dense[i].val, true
}
var v V
- return v
+ return v, false
}
func (s *genericSparseMap[K, V]) set(k K, v V) {
}
// get returns the int32 associated with the file index and line of p.
-func (m *xposmap) get(p src.XPos) int32 {
+func (m *xposmap) get(p src.XPos) (int32, bool) {
s := m.mapFor(p.FileIndex())
if s == nil {
- return -1
+ return 0, false
}
return s.get(p.Line())
}