power: Cache SOC ID checks for future queries
Currently, get_soc_id() is queried on every SOC ID check in the
SDM660, MSM8916, MSM8952, MSM8953 and MSM8974-family HALs.
This results in extraneous file operations on every SOC ID check.
Cache the result of get_soc_id() during the first query to
reduce the number of file operations being made.
This also brings back the behaviour in LineageOS 15.1 when the
HALs were still stored in device/qcom/common.
Change-Id: Ic17dbf12e7f9ecdb47b73a580f467df9ad630aa0
diff --git a/power-660.c b/power-660.c
index c529d15..627d15b 100644
--- a/power-660.c
+++ b/power-660.c
@@ -57,17 +57,16 @@
static void process_video_encode_hint(void* metadata);
/**
- * If target is SDM630/SDM455:
- * return true
- * else:
- * return false
+ * Returns true if the target is SDM630/SDM455.
*/
static bool is_target_SDM630(void) {
- static bool is_SDM630 = false;
+ static int is_SDM630 = -1;
int soc_id;
+ if (is_SDM630 >= 0) return is_SDM630;
+
soc_id = get_soc_id();
- if (soc_id == 318 || soc_id == 327 || soc_id == 385) is_SDM630 = true;
+ is_SDM630 = soc_id == 318 || soc_id == 327 || soc_id == 385;
return is_SDM630;
}
diff --git a/power-8937.c b/power-8937.c
index ea9f43a..f02cfb2 100644
--- a/power-8937.c
+++ b/power-8937.c
@@ -56,17 +56,16 @@
static void process_video_encode_hint(void* metadata);
/**
- * If target is SDM439/429:
- * return true
- * else:
- * return false
+ * Returns true if the target is SDM439/SDM429.
*/
static bool is_target_SDM439(void) {
- static bool is_SDM439 = false;
+ static int is_SDM439 = -1;
int soc_id;
+ if (is_SDM439 >= 0) return is_SDM439;
+
soc_id = get_soc_id();
- if (soc_id == 353 || soc_id == 363 || soc_id == 354 || soc_id == 364) is_SDM439 = true;
+ is_SDM439 = soc_id == 353 || soc_id == 363 || soc_id == 354 || soc_id == 364;
return is_SDM439;
}
diff --git a/power-8953.c b/power-8953.c
index b2d7d12..f7f785a 100644
--- a/power-8953.c
+++ b/power-8953.c
@@ -57,17 +57,16 @@
static void process_video_encode_hint(void* metadata);
/**
- * If target is SDM632:
- * return true
- * else:
- * return false
+ * Returns true if the target is SDM632.
*/
static bool is_target_SDM632(void) {
- static bool is_SDM632 = false;
+ static int is_SDM632 = -1;
int soc_id;
+ if (is_SDM632 >= 0) return is_SDM632;
+
soc_id = get_soc_id();
- if (soc_id == 349 || soc_id == 350) is_SDM632 = true;
+ is_SDM632 = soc_id == 349 || soc_id == 350;
return is_SDM632;
}