Skip to content

Commit 42e6598

Browse files
committed
Remove the try-catch block when trying to deserialize. Instead, we compare the BLOB to the expected first 18 bytes of a serialized Serialization object. This should avoid the performance hit of the try-catch block while being quite a bit cleaner code. The only disadvantage is if the expected serialization bytes change at some point. We could possibly add a check for a certain serialization version (I think this is kept track of in Base) to make sure things throw an error instead of failing miserably.
1 parent 7b13fbc commit 42e6598

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/SQLite.jl

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,13 @@ function execute(db::SQLiteDB,sql::AbstractString)
176176
return changes(db)
177177
end
178178

179+
const SERIALIZATION = UInt8[0x11,0x01,0x02,0x0d,0x53,0x65,0x72,0x69,0x61,0x6c,0x69,0x7a,0x61,0x74,0x69,0x6f,0x6e,0x23]
179180
function sqldeserialize(r)
180-
# try blocks introduce new scope
181-
local v
182-
# deserialize will sometimes, but not consistently (see comment in
183-
# sqlserialize), throw an error when called on an object which hasn't been
184-
# previously serialized
185-
try
181+
ret = ccall(:memcmp, Int32, (Ptr{UInt8},Ptr{UInt8}, UInt),
182+
SERIALIZATION, r, min(18,length(r)))
183+
184+
if ret == 0
186185
v = deserialize(IOBuffer(r))
187-
catch
188-
return r
189-
end
190-
if isa(v, Serialization)
191186
return v.object
192187
else
193188
return r

0 commit comments

Comments
 (0)