@@ -228,6 +228,34 @@ protected Object recurse(QDLStem in, IndexArgs sourceIndices) {
228228 int startIndex = 1 ;
229229 IndexArg root = indexArgs .get (startIndex );
230230 long autoIndex = 0L ;
231+ boolean isList = indexArgs .size () == 2 ; // This does list processing only
232+ // Very simple case of list only -- this is just an optimization for a very common case, so we don't
233+ // start the recursion.
234+ if (isList ) {
235+ for (Object key : root .createKeySet (in )) {
236+ Object value = in .get (key );
237+ if (Constant .isScalar (root .swri .getResult ())) {
238+ if (value == null ) {
239+ // edge case, they asked for a non-existent index
240+ // E.g. v.:=[;5]; v\42;
241+ return QDLNull .getInstance ();
242+ }
243+ return value ;
244+ }
245+ if (value == null ) {
246+ continue ;
247+ }
248+ if (root .strictOrder || (key instanceof String )) {
249+ out .putLongOrString (key , value );
250+ } else {
251+ out .put (autoIndex ++, value );
252+
253+ }
254+ } // end for
255+ return out ;
256+ }
257+
258+
231259 for (Object key : root .createKeySet (in )) {
232260 Object value = in .get (key );
233261 if (value == null ) {
@@ -239,6 +267,7 @@ protected Object recurse(QDLStem in, IndexArgs sourceIndices) {
239267
240268 continue ;
241269 }
270+
242271 if (value instanceof QDLStem ) {
243272 IndexList indexList = new IndexList ();
244273
@@ -256,20 +285,24 @@ protected Object recurse(QDLStem in, IndexArgs sourceIndices) {
256285 otherOut = recurse ((QDLStem ) value , out , indexList , sourceIndices , startIndex + 1 , 0L );
257286 } else {
258287 if (indexArgs .size () - 1 == startIndex ) {
288+ System .out .println ("recurse: last args index size =" + (indexArgs .size () - 1 ));
259289 // set the value, but only if it is the end of an index list (so there
260290 // are no more indices to traverse.
261291 if (root .isWildcard ()) {
292+ System .out .println (" set wildcard key=" + key + ", value=" + value );
262293 out .putLongOrString (key , value );
263294 } else {
264295 if (Constant .isScalar (root .swri .getResult ())) {
296+ System .out .println (" return value=" + value );
265297 return value ;
266298 } else {
267299 if (root .strictOrder || (key instanceof String )) {
300+ System .out .println (" put key=" + key + ", value=" + value );
268301 out .putLongOrString (key , value );
269302 } else {
303+ System .out .println (" autoindex put key=" + key + ", value=" + value );
270304 out .put (autoIndex ++, value );
271305 }
272-
273306 }
274307
275308 }
@@ -286,18 +319,28 @@ protected Object recurse(QDLStem in, IndexArgs sourceIndices) {
286319 }
287320
288321 protected Object recurse (QDLStem in ,
289- QDLStem out ,
290- IndexList targetIndex ,
291- List <IndexArg > sourceIndices ,
292- int indexLocation ,
293- long strictIndex ) {
322+ QDLStem out ,
323+ IndexList targetIndex ,
324+ List <IndexArg > sourceIndices ,
325+ int indexLocation ,
326+ long strictIndex ) {
294327
295328 if (sourceIndices .size () <= indexLocation ) {
296- System .out .println ("*** recurseNEW: targetIndex = " + targetIndex + ", strictIndex=" + strictIndex + ", loc=" + indexLocation + ", in=" + in + ", out=" + out );
329+ System .out .println ("*** recurseNEW: " +
330+ "\n in=" + in +
331+ "\n out=" + out +
332+ "\n targetIndex = " + targetIndex +
333+ "\n sourceIndices = " + sourceIndices +
334+ "\n loc=" + indexLocation +
335+ "\n strictIndex=" + strictIndex
336+ );
297337 IndexArg lastIndex = sourceIndices .get (indexLocation - 1 );
298338 if (Constant .isScalar (lastIndex .swri .getResult ())) {
339+ System .out .println (" recurseNEW: adding all inStem" );
299340 out .addAll (in );
300341 } else {
342+ System .out .println (" recurseNEW: strict add inStem" );
343+
301344 out .putLongOrString (strictIndex , in );
302345 }
303346 return out ;
@@ -339,34 +382,36 @@ protected Object recurse(QDLStem in,
339382 }
340383 out .set (indexList , value );
341384 }
342- // System.out.println("recurse: setting value key =" + indexList + ", value = " + value);
385+ System .out .println (" recurseNEW: setting value key =" + indexList + ", value = " + value );
386+ }else {
387+ if (value instanceof QDLStem ) {
388+ IndexList indexList = targetIndex .clone ();
389+ if (indexLocation + 1 < sourceIndices .size ()) {
390+ // System.out.println("recurseNEW: INDEX CHECK, targetIndex = " + targetIndex + ", strictIndex=" + strictIndex + ", loc=" + indexLocation + ", in=" + in + ", out=" + out);
391+ }
392+
393+ if ((indexArg .swri instanceof AllIndices ) || !Constant .isScalar (indexArg .swri .getResult ())) {
394+ if (indexArg .strictOrder && indexArg .isWildcard ()) {
395+ indexList .add (key );
396+ } else {
397+ indexList .add (strictIndex ++);
398+ }
399+ }
400+ if (sourceIndices .size () <= indexLocation ) {
401+ IndexArg lastIndex = sourceIndices .get (indexLocation - 1 );
402+ if (Constant .isScalar (lastIndex .swri .getResult ())) {
403+ out .addAll (in );
404+ } else {
405+ out .putLongOrString (strictIndex ++, in );
406+ }
407+
408+ } else {
409+ otherOut = recurse ((QDLStem ) value , out , indexList , sourceIndices , indexLocation + 1 , 0L );
410+ }
411+ }
343412 }
344413
345- if (value instanceof QDLStem ) {
346- IndexList indexList = targetIndex .clone ();
347- if (indexLocation + 1 < sourceIndices .size ()) {
348- // System.out.println("recurseNEW: INDEX CHECK, targetIndex = " + targetIndex + ", strictIndex=" + strictIndex + ", loc=" + indexLocation + ", in=" + in + ", out=" + out);
349- }
350414
351- if ((indexArg .swri instanceof AllIndices ) || !Constant .isScalar (indexArg .swri .getResult ())) {
352- if (indexArg .strictOrder && indexArg .isWildcard ()) {
353- indexList .add (key );
354- } else {
355- indexList .add (strictIndex ++);
356- }
357- }
358- if (sourceIndices .size () <= indexLocation ) {
359- IndexArg lastIndex = sourceIndices .get (indexLocation - 1 );
360- if (Constant .isScalar (lastIndex .swri .getResult ())) {
361- out .addAll (in );
362- } else {
363- out .putLongOrString (strictIndex ++, in );
364- }
365-
366- } else {
367- otherOut = recurse ((QDLStem ) value , out , indexList , sourceIndices , indexLocation + 1 , 0L );
368- }
369- }
370415 }
371416 if (!(otherOut instanceof QDLStem )) {
372417 return otherOut ;
0 commit comments