(models []*ModelInfo, extras ...*ModelInfo)
| 208 | } |
| 209 | |
| 210 | func upsertModelInfos(models []*ModelInfo, extras ...*ModelInfo) []*ModelInfo { |
| 211 | if len(extras) == 0 { |
| 212 | return models |
| 213 | } |
| 214 | |
| 215 | extraIDs := make(map[string]struct{}, len(extras)) |
| 216 | extraList := make([]*ModelInfo, 0, len(extras)) |
| 217 | for _, extra := range extras { |
| 218 | if extra == nil { |
| 219 | continue |
| 220 | } |
| 221 | id := strings.TrimSpace(extra.ID) |
| 222 | if id == "" { |
| 223 | continue |
| 224 | } |
| 225 | key := strings.ToLower(id) |
| 226 | if _, exists := extraIDs[key]; exists { |
| 227 | continue |
| 228 | } |
| 229 | extraIDs[key] = struct{}{} |
| 230 | extraList = append(extraList, cloneModelInfo(extra)) |
| 231 | } |
| 232 | |
| 233 | if len(extraList) == 0 { |
| 234 | return models |
| 235 | } |
| 236 | |
| 237 | filtered := make([]*ModelInfo, 0, len(models)+len(extraList)) |
| 238 | for _, model := range models { |
| 239 | if model == nil { |
| 240 | continue |
| 241 | } |
| 242 | id := strings.TrimSpace(model.ID) |
| 243 | if id == "" { |
| 244 | continue |
| 245 | } |
| 246 | if _, exists := extraIDs[strings.ToLower(id)]; exists { |
| 247 | continue |
| 248 | } |
| 249 | filtered = append(filtered, model) |
| 250 | } |
| 251 | |
| 252 | filtered = append(filtered, extraList...) |
| 253 | return filtered |
| 254 | } |
| 255 | |
| 256 | // cloneModelInfos returns a shallow copy of the slice with each element deep-cloned. |
| 257 | func cloneModelInfos(models []*ModelInfo) []*ModelInfo { |
no test coverage detected