isPointerPlusAcc checks if the node represents `# + #acc` pattern
(node Node)
| 69 | |
| 70 | // isPointerPlusAcc checks if the node represents `# + #acc` pattern |
| 71 | func isPointerPlusAcc(node Node) bool { |
| 72 | predicate, ok := node.(*PredicateNode) |
| 73 | if !ok { |
| 74 | return false |
| 75 | } |
| 76 | |
| 77 | binary, ok := predicate.Node.(*BinaryNode) |
| 78 | if !ok { |
| 79 | return false |
| 80 | } |
| 81 | |
| 82 | if binary.Operator != "+" { |
| 83 | return false |
| 84 | } |
| 85 | |
| 86 | // Check for # + #acc (pointer + accumulator) |
| 87 | leftPointer, leftIsPointer := binary.Left.(*PointerNode) |
| 88 | rightPointer, rightIsPointer := binary.Right.(*PointerNode) |
| 89 | |
| 90 | if leftIsPointer && rightIsPointer { |
| 91 | // # + #acc: Left is pointer (Name=""), Right is acc (Name="acc") |
| 92 | if leftPointer.Name == "" && rightPointer.Name == "acc" { |
| 93 | return true |
| 94 | } |
| 95 | // #acc + #: Left is acc (Name="acc"), Right is pointer (Name="") |
| 96 | if leftPointer.Name == "acc" && rightPointer.Name == "" { |
| 97 | return true |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return false |
| 102 | } |
| 103 | |
| 104 | // applySumPredicate tries to compute the result of sum(m..n, predicate) at compile time. |
| 105 | // Returns (result, true) if optimization is possible, (0, false) otherwise. |
no outgoing calls
no test coverage detected
searching dependent graphs…