Skip to content

Commit f6d30cf

Browse files
kaja47nikic
authored andcommitted
microptimization of SQLite3Result::fetchArray
Store the result of sqlite3_data_count() into a variable and check that inside a loop instead calling it directly all the time. GCC is not brave enough to figure out the function produces the same result every time and call it repeatedly. This change produces fairly small but measurable and consistent speedup.
1 parent 1347d90 commit f6d30cf

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ext/sqlite3/sqlite3.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1946,8 +1946,10 @@ PHP_METHOD(SQLite3Result, fetchArray)
19461946
}
19471947

19481948
array_init(return_value);
1949+
1950+
int column_count = sqlite3_data_count(result_obj->stmt_obj->stmt);
19491951

1950-
for (i = 0; i < sqlite3_data_count(result_obj->stmt_obj->stmt); i++) {
1952+
for (i = 0; i < column_count; i++) {
19511953
zval data;
19521954

19531955
sqlite_value_to_zval(result_obj->stmt_obj->stmt, i, &data);

0 commit comments

Comments
 (0)