concat bug?
concat bug?
Xbytor, in my notes I have an old post( not sure how old ) from you where you say that sometimes Array.concat() fails in ExtendScipt. Do you know if that has been fixed?
concat bug?
I do see this code in xtools:
Code: Select all//
// Stdlib.findFiles is a recursive version of Stdlib.getFiles
//
Stdlib.findFiles = function(folder, mask) {
var files = Stdlib.getFiles(folder, mask);
var folders = Stdlib.getFolders(folder);
for (var i = 0; i < folders.length; i++) {
var f = folders;
var ffs = Stdlib.findFiles(f, mask);
// files.concat(ffs); This occasionally fails for some unknown reason (aka
// interpreter Bug) so we do it manually instead
while (ffs.length > 0) {
files.push(ffs.shift());
}
}
return files;
};
Dunno what the issue was though.
Code: Select all//
// Stdlib.findFiles is a recursive version of Stdlib.getFiles
//
Stdlib.findFiles = function(folder, mask) {
var files = Stdlib.getFiles(folder, mask);
var folders = Stdlib.getFolders(folder);
for (var i = 0; i < folders.length; i++) {
var f = folders;
var ffs = Stdlib.findFiles(f, mask);
// files.concat(ffs); This occasionally fails for some unknown reason (aka
// interpreter Bug) so we do it manually instead
while (ffs.length > 0) {
files.push(ffs.shift());
}
}
return files;
};
Dunno what the issue was though.
concat bug?
I would also be very curious to know if there are issues w/ concat, and under what circumstances and in what PS versions, and what exactly the effects were (wrong output? thrown errors?). It also might be possible to do something like:
Code: Select allvar _tmp; // <-- put at top of function or wherever
((_tmp = arr1.slice(0)), _tmp.push.apply(out, arr2), _tmp)
// to replace
arr1.concat(arr2)
Or even a general-purpose:
Code: Select allvar concat = function () { // accepts any number of arrays
var i, n, out, push;
if (arguments.length === 0) { return []; }
push = Array.prototype.push;
out = Array.prototype.slice.call(arguments[0], 0); // shallow copy first arg
for (i = 1, n = arguments.length; i < n; i++) {
push.apply(out, arguments);
}
return out;
};
concat(arr1, arr2, arr3)
Or added to the Array prototype:
Code: Select allArray.prototype.concat2 = function () { // accepts any number of arrays
var i, n, out, push;
push = Array.prototype.push;
out = Array.prototype.slice.call(this, 0); // shallow copy
for (i = 0, n = arguments.length; i < n; i++) {
push.apply(out, arguments);
}
return out;
};
arr1.concat2(arr2, arr3)
But if concat is broken, then other array methods might also have problems.
Code: Select allvar _tmp; // <-- put at top of function or wherever
((_tmp = arr1.slice(0)), _tmp.push.apply(out, arr2), _tmp)
// to replace
arr1.concat(arr2)
Or even a general-purpose:
Code: Select allvar concat = function () { // accepts any number of arrays
var i, n, out, push;
if (arguments.length === 0) { return []; }
push = Array.prototype.push;
out = Array.prototype.slice.call(arguments[0], 0); // shallow copy first arg
for (i = 1, n = arguments.length; i < n; i++) {
push.apply(out, arguments);
}
return out;
};
concat(arr1, arr2, arr3)
Or added to the Array prototype:
Code: Select allArray.prototype.concat2 = function () { // accepts any number of arrays
var i, n, out, push;
push = Array.prototype.push;
out = Array.prototype.slice.call(this, 0); // shallow copy
for (i = 0, n = arguments.length; i < n; i++) {
push.apply(out, arguments);
}
return out;
};
arr1.concat2(arr2, arr3)
But if concat is broken, then other array methods might also have problems.
concat bug?
Mike Hale wrote:Do you know if that has been fixed?
I haven't checked in awhile. I noticed the bug back in the CS/SC2 era. I should probably find reproducible test case and find out which versions of PS have the bug.
I haven't checked in awhile. I noticed the bug back in the CS/SC2 era. I should probably find reproducible test case and find out which versions of PS have the bug.