Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

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

Open
sayandipdutta opened this issue Feb 4, 2022 · 3 comments · May be fixed by #615
Open

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

sayandipdutta opened this issue Feb 4, 2022 · 3 comments · May be fixed by #615
Labels
Area-Build Affects CI pipelines and other build processes Kind-Maintenance Request or suggestion for general code quality improvements

Comments

@sayandipdutta
Copy link

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
Copy link
Author

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

@cgranade cgranade added Kind-Maintenance Request or suggestion for general code quality improvements Area-Build Affects CI pipelines and other build processes labels Feb 24, 2022
@cgranade
Copy link
Contributor

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

@sayandipdutta
Copy link
Author

Sure, I will add one today.

sayandipdutta added a commit to sayandipdutta/Quantum that referenced this issue Feb 25, 2022
Avoid double iteration by removing `list` call on a `list` object.
@sayandipdutta sayandipdutta linked a pull request Feb 25, 2022 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area-Build Affects CI pipelines and other build processes Kind-Maintenance Request or suggestion for general code quality improvements
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants