12/08/22 00:09:49.86 .net
size: 656 byte, supports -o -v option. Array A and B can be the same (NEW)
function xagrep( o, re, A, B, this, a, i,k ){
k=0;B[0]=A[0];if(o~"-v"){for(i=1;i<=A[0];i++){if(!match(A[i],re)) B[k+=1]=A[i];}B[0]=k;return k};
if(o~"-o"){B[B[0]+1]=0;for(i=1;i<=A[0];i++){a=A[i];if(i==k){i=i-B[B[0]+1]+1;B[B[0]+1]=k;k=B[0]+2;
while(i<=B[B[0]+1]){B[i++]=B[k];delete B[k++];}i=B[B[0]+1];k=i;B[B[0]+1]=0;}while(match(a,re)){
if(i>k){B[k+=1]=substr(a,RSTART,RLENGTH);}else{B[B[0]+1+(B[B[0]+1]+=1)]=substr(a,RSTART,RLENGTH);
k++}a=substr(a,RSTART+RLENGTH)}}if(i<k){i=k-i;k=B[0]+1;B[0]=i+B[B[0]+1];while(i<B[0])B[i+=1]=B[k+=1];
while(i<k)delete B[i+=1];}return B[0]}for(i=1;i<=A[0];i++){if(match(A[i],re))B[k+=1]=A[i];}B[0]=k;return k;
}
これ以上削れるところ無いかな?
高速化+サイズ優先で、変数はできるだけ使う数を少なくとの条件で