- idx = amount - 1;
- while ((idx >= 0) && (peer_count > top100c[idx].val))
- --idx;
- if (idx++ != amount - 1) {
- memmove(top100c + idx + 1, top100c + idx, (amount - 1 - idx) * sizeof(ot_record));
- memcpy(&top100c[idx].hash, &torrent->hash, sizeof(ot_hash));
- top100c[idx].val = peer_count;
- }
- idx = amount - 1;
- while ((idx >= 0) && (seed_count > top100s[idx].val))
- --idx;
- if (idx++ != amount - 1) {
- memmove(top100s + idx + 1, top100s + idx, (amount - 1 - idx) * sizeof(ot_record));
- memcpy(&top100s[idx].hash, &torrent->hash, sizeof(ot_hash));
- top100s[idx].val = seed_count;
- }
- idx = amount - 1;
- while ((idx >= 0) && (leech_count > top100l[idx].val))
- --idx;
- if (idx++ != amount - 1) {
- memmove(top100l + idx + 1, top100l + idx, (amount - 1 - idx) * sizeof(ot_record));
- memcpy(&top100l[idx].hash, &torrent->hash, sizeof(ot_hash));
- top100l[idx].val = leech_count;
- }
+
+ stats_insert_into_highscore(peer_count, top100c, amount, &torrent->hash);
+ stats_insert_into_highscore(seed_count, top100s, amount, &torrent->hash);
+ stats_insert_into_highscore(leech_count, top100l, amount, &torrent->hash);