lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Unfortunately, my timing runs show that your
suggestion makes no measurable difference. Any other
suggestions would be welcomed.

--- Romulo Bahiense <romulo@icontroller.com.br> wrote:

> I believe the problem is not table allocation, but
> index access and 
> length calculation ('#' operator).
> 
> Try this one:
> 
> function createFieldDataEntriesForOneDataGenerator(
> dataGenerator )
> 
>      local data = dataGenerator()
> 
>      local iSubTable      = 0
>      local iSubTableBlock = 0
> 
>      local subTable      = {}
>      local subTableBlock = {}
> 
>      local subTableType
> 
>      for i, element in ipairs(data) do
>          local a, b, c = element[ 1 ], element[ 2 ],
> element[ 3 ]
>          if a == "<type>" then
>              subTableType = b
>          elseif a == "</type>" then
>              -- do nothing
>          elseif a == "<block>" then
>              subTableBlock = {Number=b,Dup=c}
>          elseif a == "</block>" then
>              iSubTable = iSubTable + 1
>              subTable[iSubTable] = subTableBlock
>          else
>              if trim(b) ~= "" then
>                  iSubTableBlock = iSubTableBlock + 1
>                  subTableBlock[ iSubTableBlock ] =
> {a,b}
>              end
>          end
>      end
> 
>      return subTable, subTableType
> end
> 
> Note that, in this code, 'data[i]' is the same as
> 'element', because 
> ipairs return key and value.
> 
> --rb
>