HasDuplicates reports whether f contains any duplicate setting IDs.
()
| 837 | |
| 838 | // HasDuplicates reports whether f contains any duplicate setting IDs. |
| 839 | func (f *SettingsFrame) HasDuplicates() bool { |
| 840 | num := f.NumSettings() |
| 841 | if num == 0 { |
| 842 | return false |
| 843 | } |
| 844 | // If it's small enough (the common case), just do the n^2 |
| 845 | // thing and avoid a map allocation. |
| 846 | if num < 10 { |
| 847 | for i := 0; i < num; i++ { |
| 848 | idi := f.Setting(i).ID |
| 849 | for j := i + 1; j < num; j++ { |
| 850 | idj := f.Setting(j).ID |
| 851 | if idi == idj { |
| 852 | return true |
| 853 | } |
| 854 | } |
| 855 | } |
| 856 | return false |
| 857 | } |
| 858 | seen := map[http2.SettingID]bool{} |
| 859 | for i := 0; i < num; i++ { |
| 860 | id := f.Setting(i).ID |
| 861 | if seen[id] { |
| 862 | return true |
| 863 | } |
| 864 | seen[id] = true |
| 865 | } |
| 866 | return false |
| 867 | } |
| 868 | |
| 869 | // ForeachSetting runs fn for each setting. |
| 870 | // It stops and returns the first error. |
nothing calls this directly
no test coverage detected