PSSH: Optimize how overwrite_key_ids works with the repeated field

We can clear a repeated field with `del field[:]` and overwrite an entire field with `field[:] = [b"123", b"456"]`. So we can reduce this down to a single call operation.
This commit is contained in:
rlaphoenix 2022-08-05 07:35:34 +01:00
parent 10fb954097
commit 76c7a402eb
1 changed files with 4 additions and 7 deletions

View File

@ -270,13 +270,10 @@ class PSSH:
init = WidevinePsshData() init = WidevinePsshData()
init.ParseFromString(box.init_data) init.ParseFromString(box.init_data)
# TODO: Is there a better way to clear the Key IDs? init.key_ids[:] = [
for _ in range(len(init.key_ids or [])): key_id.bytes
init.key_ids.pop(0) for key_id in key_ids
]
# TODO: Is there a .extend or a way to add all without a loop?
for key_id in key_ids:
init.key_ids.append(key_id.bytes)
box.init_data = init.SerializeToString() box.init_data = init.SerializeToString()