stephencelis / SQLite.swift

A type-safe, Swift-language layer over SQLite3.
MIT License
9.57k stars 1.54k forks source link

Improve string quote performance #1132

Closed justinmeiners closed 2 years ago

justinmeiners commented 2 years ago

The quote function was showing up in my instruments profile. The current implementation requires an allocation of a one or more strings at every step of the reduce. This version adds one character at a time and relies on the geometric growth of the string itself. I personally think it's a little clearer as well.

I considered adding reserveCapacity to the beginning, but that might be a bit of a micro-optimization.