instead of iterating the table and then the match list take a look at `ets:select/2`:

```erlang
held_locks_match() ->
    T = ets:new(undefined, [bag]),
    ets:insert(T, [{{held, type1}, a}, {{held, type1}, b}, {{held, type2}, a}, {{held, type1}, c}]),
    Res1 = [Lock || {{held, _Type},Lock} <- ets:match_object(T, {{held, '_'},'_'})],
    Res2 = ets:select(T, [{{{held, '_'}, '$1'},[],['$1']}]),
    ets:delete(T),
    {Res1, Res2, lists:usort(Res1) =:= lists:usort(Res2)}.
```