doberkofler / PLSQL-JSON

The JSON encode/decode library for Oracle PL/SQL
MIT License
47 stars 15 forks source link

Suggestion for performance improvement in json_utils.escape #6

Closed RaLuethke closed 4 years ago

RaLuethke commented 8 years ago

Hi, I also want to thank you for your code, the performance is already much better than the original PL/JSON package. But I have a suggestion for further performance improvement of the to_clob() functionality. The idea is to shortcut the character by character conversion loop, when the input string of the escape function only contains valid ascii characters:

IF (theString IS NULL) THEN
    RETURN '';
ElsIf Translate(theString, '\ !#$%&''()*+,-.0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~', '\') Is Null Then
    -- theString contains only characters with ascii codes 32, 33, 35..46, 48..91, 93..126
    Return theString;
END IF;

What are your thoughts on this? Am I missing something? Thanks, Ralf

doberkofler commented 4 years ago

Thank you for the input, but according to my tests if would have very little (about 1%) performance impact on strings that must be converted and would slow down (about 5%) strings that must be converted.