• Based on a lot of copy/paste, trial and error, E.memoryArea works for strings.
    function jsvStringIteratorGetChar in jsviterator.h is extend to handle native string

    static ALWAYS_INLINE char jsvStringIteratorGetChar(JsvStringIterat­or *it) {
      if (!it->ptr) return 0;
      if (jsvIsNativeString(it->var)){
        int addr = (int)it->ptr + (int)it->charIdx;
    	uint32_t bytes = *(uint32_t*)(addr & ~3);
    	return ((uint8_t*)&bytes)[(int)addr & 3];
      }
      else return it->ptr[it->charIdx];
    }
    

    In next step function jslNextCh in jslex.c is extended too and first test calling a simple function works fine.

    static ALWAYS_INLINE char jslNextCh(JsLex *lex) {
      if(jsvIsNativeString(lex->it.var)){
    	int addr = (int)lex->it.ptr + (int)lex->it.charIdx;
    	uint32_t bytes = *(uint32_t*)(addr & ~3);
    	return ((uint8_t*)&bytes)[(int)addr & 3];
      }
      else return (char)(lex->it.ptr ? lex->it.ptr[lex->it.charIdx] : 0);
    }
    

    Pretty sure there is a nicer way doing this, and we will see this in next version.
    Anyway, it opened a new door of knowledge for me.

About

Avatar for JumJum @JumJum started