function MyFunc(const Value: Integer): Integer;
const
MyArray: array[0..255] of Byte = ( ... ); // values of the array here
begin
... // Some codes here
Result := Integer(MyArray[Value shr 58]);
end;
Run Code Online (Sandbox Code Playgroud)
会声明MyArray
外面MyFunc
增加反复调用的性能MyFunc
吗?
会声明
MyArray
外部MyFunc
增加反复调用MyFunc的性能吗?
不会.编译器将生成相同的代码,无论MyArray
函数是本地的,还是更广泛的常量.类型化常量存储在可执行文件的数据段中,而不管其范围如何.