﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
3844	Unnecessary array instantiations	Rüdiger Franke	somebody	"Examples that use arrays often result in huge code because OpenModelica instantiates these arrays over and over again. Have for instance a look the `Modelica.Media.Examples.R134a.*` examples.

Here is a simpler version:
{{{#!mo
package ArrayData
  constant Integer[:] cdata = {1, 2, 3, 4, 5, 6, 7, 8, 9};

  function f
    input Integer[:] idata;
    input Integer idx;
    output Integer y;
  algorithm
    y := idata[idx] + cdata[idx] + cdata[idx + 1];
  end f;
  
  model Test
    input Integer idx = 0;
    parameter Integer[:] pdata = cdata;
    Integer y = f(pdata, idx+1);
  end Test;
end ArrayData;
}}}

`ArrayData.Test` is instantiated to:
{{{#!mo
function ArrayData.f
  input Integer[:] idata;
  input Integer idx;
  output Integer y;
algorithm
  y := idata[idx] + {1, 2, 3, 4, 5, 6, 7, 8, 9}[idx] + {1, 2, 3, 4, 5, 6, 7, 8, 9}[1 + idx];
end ArrayData.f;

class ArrayData.Test
  input Integer idx = 0;
  parameter Integer pdata[1] = 1;
  parameter Integer pdata[2] = 2;
  parameter Integer pdata[3] = 3;
  parameter Integer pdata[4] = 4;
  parameter Integer pdata[5] = 5;
  parameter Integer pdata[6] = 6;
  parameter Integer pdata[7] = 7;
  parameter Integer pdata[8] = 8;
  parameter Integer pdata[9] = 9;
  Integer y = ArrayData.f({pdata[1], pdata[2], pdata[3], pdata[4], pdata[5], pdata[6], pdata[7], pdata[8], pdata[9]}, 1 + idx);
end ArrayData.Test;
}}}

It is bad if a temporary array is created when calling the function `f`, instead of just passing `pdata`. It is worse if the whole `cdata` array is created temporarily again and again whenever the function `f` wants to access one element of it.
"	defect	new	high	2.0.0	Frontend				
