简体   繁体   English

如何在javascript中创建将大量字符串元素推送到数组中而不会出错

[英]How to create push a large number of string elements into array in javascript without error

I'm using the following function to take a large array of strings (user names) and check them for single quotes, then push them into my new array and return that.我正在使用以下函数来获取大量字符串(用户名)并检查它们是否有单引号,然后将它们推送到我的新数组中并返回。

Recently, the number of users in this list increased dramatically (7418 currently) and now this function is getting an error:最近,此列表中的用户数量急剧增加(目前为 7418),现在此功能出现错误:

Caused by: java.lang.ClassFormatError: Invalid method Code length 105684 in class file org/mozilla/javascript/gen/c135516引起:java.lang.ClassFormatError: Invalid method Code length 105684 in class file org/mozilla/javascript/gen/c135516

The version of javascript is embedded in the application so upgrading that is not an option at this time. javascript 版本嵌入在应用程序中,因此目前无法进行升级。

Is there a better way to do this?有一个更好的方法吗? or a different way to try to avoid this error?或尝试避免此错误的不同方法?

function listExcludedUsers(rInactive) {
    var result = new Array('user1', 'user2', 'user3', 'user4');

    for (var i = 0; i < rInactive.length; i++) {
        //replace single quote with two single quotes for DQL
        if (rInactive[i].indexOf("'") > 0) {
            rInactive[i] = rInactive[i].replace(/'/g, "''");
        }
        result.push(rInactive[i]);
    }
    return result;
}

Thhe JVM restricts the length of methods to 65536 bytes, so it seems as if you have found a bug in Mozilla. JVM 将方法的长度限制为 65536 字节,因此您似乎在 Mozilla 中发现了错误。 Please file it (with example if possible) at https://bugzilla.mozilla.org/ .请在https://bugzilla.mozilla.org/ 上提交(如果可能,提供示例)。

Meanwhile: try to cut your method in multiple smaller parts, eg: chop the input and push it into several smaller arrays and concatenate those at the end.同时:尝试将您的方法切成多个较小的部分,例如:将输入切碎并将其推入几个较小的数组中,并在最后将它们连接起来。 You should do it with several different function s.你应该用几个不同的function来做。

This code looks like you are running a jvm that does not take very long methods name and those methods are because of the JavaScript input you are giving, it would be nice to try to reproduce the case, I would这段代码看起来你正在运行一个不需要很长方法名称的 jvm 并且这些方法是因为你提供的 JavaScript 输入,尝试重现这种情况会很好,我会

Try to change the input of your JavaScript code that makes those methods in jvm too longs, may be in several sets of inputs.尝试更改您的 JavaScript 代码的输入,使 jvm 中的那些方法太长,可能在几组输入中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM