AppleScript文档建议以下代码有效地构建列表:
set bigList to {}
set bigListRef to a reference to bigList
set numItems to 100000
set t to (time of (current date)) --Start timing operations
repeat with n from 1 to numItems
copy n to the end of bigListRef
end
set total to (time of (current date)) - t --End timing
Run Code Online (Sandbox Code Playgroud)
注意使用显式引用.这在脚本的顶级或显式运行处理程序中工作正常,但如果您在另一个处理程序中逐字运行相同的完全代码,如下所示:
on buildList()
set bigList to {}
set bigListRef to a reference to bigList
set numItems to 100000
set t to (time of (current date)) --Start timing operations …
Run Code Online (Sandbox Code Playgroud)