Module:Punycode: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 3: Line 3:


local punycode = {}
local punycode = {}
-- Cache for frequently processed strings (persists during a single page render)
local encodeCache = {}
local decodeCache = {}


--------------------------
--------------------------
Line 82: Line 86:
--------------------------
--------------------------
function punycode.encode(input)
function punycode.encode(input)
    -- Input validation and cache check
    if not input or input == "" then
        return ""
    end
   
    -- Check cache first for previously encoded strings
    if encodeCache[input] then
        return encodeCache[input]
    end
   
     local output = {}
     local output = {}
     local cp_array = toCodePoints(input)
     local cp_array = toCodePoints(input)