public Accessor optimizeCollection(ParserContext pCtx, Object o, Class type, char[] property, int start, int offset,
                                     Object ctx, Object thisRef, VariableResolverFactory factory) {
    this.expr = property;
    this.cursor = this.start = start;
    this.end = start + offset;
    this.length = offset;

    type = toNonPrimitiveArray(type);
    this.returnType = type;

    this.compiledInputs = new ArrayList<ExecutableStatement>();

    this.ctx = ctx;
    this.thisRef = thisRef;
    this.variableFactory = factory;
    this.pCtx = pCtx;

    _initJIT();

    literal = true;

    _getAccessor(o, type);

    _finishJIT();

    try {
      Accessor compiledAccessor = _initializeAccessor();

      if (property != null && length > start) {
        return new Union(pCtx, compiledAccessor, property, start, length);
      }
      else {
        return compiledAccessor;
      }

    }
    catch (Exception e) {
      throw new OptimizationFailure("could not optimize collection", e);
    }
  }