[Cryptech-Commits] [sw/stm32] 04/04: Make stm_flash_sector_num a little more efficient.
git at cryptech.is
git at cryptech.is
Wed Dec 21 00:11:07 UTC 2016
This is an automated email from the git hooks/post-receive script.
paul at psgd.org pushed a commit to branch master
in repository sw/stm32.
commit fe94d97f705846ef809d4109b310c96d0b3bb1ac
Author: Paul Selkirk <paul at psgd.org>
AuthorDate: Tue Dec 20 19:06:29 2016 -0500
Make stm_flash_sector_num a little more efficient.
---
stm-flash.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/stm-flash.c b/stm-flash.c
index 991379b..fc79ea0 100644
--- a/stm-flash.c
+++ b/stm-flash.c
@@ -72,14 +72,15 @@ uint32_t flash_sector_offsets[FLASH_NUM_SECTORS + 1] = {
int stm_flash_sector_num(const uint32_t offset)
{
- int i = FLASH_NUM_SECTORS;
+ int i;
- while (i-- >= 0) {
- if (offset >= flash_sector_offsets[i] &&
- offset < flash_sector_offsets[i + 1]) {
+ if (offset < flash_sector_offsets[0])
+ return -1;
+
+ for (i = 0; i < FLASH_NUM_SECTORS; ++i)
+ if (offset < flash_sector_offsets[i + 1])
return i;
- }
- }
+
return -1;
}
More information about the Commits
mailing list