| 165 | } |
| 166 | |
| 167 | func (ast *Assertion) copy() *Assertion { |
| 168 | tokens := append([]string(nil), ast.Tokens...) |
| 169 | policy := make([][]string, len(ast.Policy)) |
| 170 | |
| 171 | for i, p := range ast.Policy { |
| 172 | policy[i] = append(policy[i], p...) |
| 173 | } |
| 174 | policyMap := make(map[string]int) |
| 175 | for k, v := range ast.PolicyMap { |
| 176 | policyMap[k] = v |
| 177 | } |
| 178 | |
| 179 | ast.FieldIndexMutex.RLock() |
| 180 | fieldIndexMap := make(map[string]int) |
| 181 | for k, v := range ast.FieldIndexMap { |
| 182 | fieldIndexMap[k] = v |
| 183 | } |
| 184 | ast.FieldIndexMutex.RUnlock() |
| 185 | |
| 186 | newAst := &Assertion{ |
| 187 | Key: ast.Key, |
| 188 | Value: ast.Value, |
| 189 | PolicyMap: policyMap, |
| 190 | Tokens: tokens, |
| 191 | Policy: policy, |
| 192 | FieldIndexMap: fieldIndexMap, |
| 193 | ParamsTokens: append([]string(nil), ast.ParamsTokens...), |
| 194 | RM: ast.RM, |
| 195 | CondRM: ast.CondRM, |
| 196 | } |
| 197 | |
| 198 | return newAst |
| 199 | } |