Skip to content

Commit cf0e880

Browse files
committed
Don't use writeStringToMemory
Use allocateUTF8StringOnStack instead
1 parent 5142efd commit cf0e880

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

coffee/api.coffee

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apiTemp = stackAlloc(4)
55
# Constants are defined in api-data.coffee
66
SQLite = {}
77

8-
### Represents an prepared statement.
8+
### Represents a prepared statement.
99
1010
Prepared statements allow you to have a template sql string,
1111
that you can execute multiple times with different parameters.
@@ -311,11 +311,14 @@ class Database
311311
if not @db then throw "Database closed"
312312

313313
stack = stackSave()
314+
314315
# Store the SQL string in memory. The string will be consumed, one statement
315316
# at a time, by sqlite3_prepare_v2_sqlptr.
316-
# Allocate at most 4 bytes per UTF8 char, +1 for the trailing '\0'
317-
nextSqlPtr = stackAlloc(sql.length<<2 + 1)
318-
writeStringToMemory sql, nextSqlPtr
317+
# Note that if we want to allocate as much memory as could _possibly_ be used, we can
318+
# we allocate bytes equal to 4* the number of chars in the sql string.
319+
# It would be faster, but this is probably a premature optimization
320+
nextSqlPtr = allocateUTF8OnStack(sql)
321+
319322
# Used to store a pointer to the next SQL statement in the string
320323
pzTail = stackAlloc(4)
321324

0 commit comments

Comments
 (0)