Optimize VFS search.

This commit is contained in:
Nuno Cruces
2023-10-19 15:28:46 +01:00
parent b25936dbec
commit a9dddaa86c
4 changed files with 18 additions and 15 deletions

Binary file not shown.

View File

@@ -90,22 +90,25 @@ int localtime_s(struct tm *const pTm, time_t const *const pTime) {
sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName) {
if (zVfsName) {
static sqlite3_vfs *go_vfs_list;
sqlite3_vfs *found = NULL;
for (sqlite3_vfs **next = &go_vfs_list; *next;) {
sqlite3_vfs *it = *next;
for (sqlite3_vfs *it = go_vfs_list; it; it = it->pNext) {
if (!strcmp(zVfsName, it->zName) && go_vfs_find(it->zName)) {
return it;
}
}
for (sqlite3_vfs **ptr = &go_vfs_list; *ptr;) {
sqlite3_vfs *it = *ptr;
if (go_vfs_find(it->zName)) {
if (!strcmp(zVfsName, it->zName)) found = it;
next = &it->pNext;
ptr = &it->pNext;
} else {
*next = it->pNext;
*ptr = it->pNext;
free(it);
}
}
if (found) {
return found;
}
if (go_vfs_find(zVfsName)) {
sqlite3_vfs *prev = go_vfs_list;
sqlite3_vfs *head = go_vfs_list;
go_vfs_list = malloc(sizeof(sqlite3_vfs) + strlen(zVfsName) + 1);
char *name = (char *)(go_vfs_list + 1);
strcpy(name, zVfsName);
@@ -114,7 +117,7 @@ sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName) {
.szOsFile = sizeof(struct go_file),
.mxPathname = 512,
.zName = name,
.pNext = prev,
.pNext = head,
.xOpen = go_open_wrapper,
.xDelete = go_delete,

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:816ddd36a255d2b3995f75924bdebd9dc7c4378eeccbe28176751434cfb788ca
size 508404
oid sha256:da493a827d5b2985ba80d7425092a891311633d6c80c559119f87609d0f0e02a
size 508796

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c0c551f14aeb338ab652f2bded33ba58188b76f2cb24ca076576c968341f841e
size 523315
oid sha256:c5ffb1dc0f046bb7e4ea4cd992e1d625c05c7d5cf33c78edc5a2155eb3d3c097
size 523393