Quantum icon indicating copy to clipboard operation
Quantum copied to clipboard

Optimization: Remove redundant `list` call in `check_file` in `Build/check_indents.py`

Open sayandipdutta opened this issue 4 years ago • 3 comments

In the check_file function of Build/check_indents.py, it is performing a redundant list call, on f.readlines() which itself returns a list, in line 28:

def check_file(filename : str) -> bool:
    ...
    with open(filename, 'r') as f:
        contents = list(f.readlines())
    ...

This can have impact on performance, if the file is really large. This does not have any benefit over the plain f.readlines() either.

I propose the following change:

-        contents = list(f.readlines())
+        contents = f.readlines()

sayandipdutta avatar Feb 04 '22 16:02 sayandipdutta

Would be happy to add a PR, if the above proposal sounds reasonable.

sayandipdutta avatar Feb 04 '22 16:02 sayandipdutta

Thanks for raising this, and for your patience! Would be happy if you'd still be interested in opening a PR!

cgranade avatar Feb 24 '22 20:02 cgranade

Sure, I will add one today.

sayandipdutta avatar Feb 25 '22 09:02 sayandipdutta