Subj : Re: "Code of a method longer than 65535 bytes" To : Cameron McCormack From : Igor Bukanov Date : Thu Apr 01 2004 11:54 am Cameron McCormack wrote: > Igor Bukanov wrote: > >> The web server returns Not Found for [2] > > > Hmm, forgot to copy it. It is there now. Well, I would really suggest to encode your arrays as string in one form or another. For example, for your actionTable you can use something like actionTable = new Array( decodeAction("010"...), decodeAction("000"...), ... } function decodeAction(coded) { var zeroCode = "0".charCodeAt(0); var L = coded.length; var array = new Array(L); for (var i = 0; i != L; ++i) { array[i] = coded.charCodeAt(i) - zeroZode - 1; } return array; } To save memory you may even drop decodeAction and instead of actionTable[i][j] use special access function like var codeShift = "0".charCodeAt(0) + 1; function getAction(i, j) { return actionTable[i].charCodeAt(j) - codeShift; } For other arrays you will need more elaborated decoders but with proper skim you will not only shrink the size of your JS code but also significantly reduce its loading time and memory consumption. The bottom line: in C/C++ array literals can be represented efficiently but in JavaScript and Java they are a very bad choice to represent complex automatically generated tables. > > I'd like to keep it as self contained as possible and not have to rely > on users of my script to put extra data into their SVG documents. > >> Rhino always uses interpreted mode for scripts inside eval so if you >> load somehow your script source into JS string and then call eval on >> it it should allow to exceed 64K limit. In your case as a simplest fix your can put eval arround each nested array like in the following actionTable = new Array( eval('new Array( -1, 0, -1, 0, -1, -1, -1...)'), .... ) which would be as readable as now and even faster to load in Rhino but still the special encoding would be the proper way to deal with it. Regards, Igor .