Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If statement optimization #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Tattersalt-Kanzaki
Copy link
Contributor

Got rid of unnecessary checks in if statements. These conditions are always true, as they are checked at a higher nesting level.

@brechtsanders
Copy link
Owner

Why would you get rid of these extra checks?
They are intended to catch function calls with invalid values.

@Tattersalt-Kanzaki
Copy link
Contributor Author

Tattersalt-Kanzaki commented Jan 7, 2025

Hi!

  1. I removed "data->callback" check on line 767 xlsxio/lib/xlsxio_read.c because it is already checked on line 762 of same file;

  2. I removed "data->colnr > 0" check on line 1145 xlsxio/lib/xlsxio_read.c because it is already checked on line 1136 of same file;

  3. I removed "!handle->sheetopen" check on line 918 xlsxio/lib/xlsxio_write.c because it is already checked on line 901 of same file.

@Tattersalt-Kanzaki
Copy link
Contributor Author

File xlsxio/lib/xlsxio_read.c
1

As we see here statement (data->callback != 0) is already checked, so we can get rid of "if" statement on line 767.

@Tattersalt-Kanzaki
Copy link
Contributor Author

File xlsxio/lib/xlsxio_read.c
2

We can get rid of check data->color > 0 (line 1145) because data->color was assigned from cellcolnr (line 1139) which is positive (check on line 1136). Also data->colnr can't be negative because it is declared as size_t;

@Tattersalt-Kanzaki
Copy link
Contributor Author

File xlsxio/lib/xlsxio_write.c
3

We can get rid of check !handle->sheetopen (line 918) because this check is happening in else statement of check handle->sheetopen (line 901).

@Tattersalt-Kanzaki
Copy link
Contributor Author

@brechtsanders, I hope I've managed to explain my pull request.
If something is wrong, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants