gpt4 book ai didi

user-interface - 加速 ComposableModel 新 openWithSpec(在 Pharo v3 中)

转载 作者:行者123 更新时间:2023-12-04 23:48:48 28 4
gpt4 key购买 nike

我需要一个带有 81 个框的 GUI,用户可以在其中选择输入一个数字(是游戏的棋盘)。

所以我子类化了一个 ComposableModel有 81 个实例变量,每个实例变量初始化为一个新的 TextInputFieldModel实例。

问题是打开大约需要6秒。为什么打开81个文本框需要这么长时间?我可以做些什么来加快打开速度?

最佳答案

您可以为此使用 Profiler。我尝试重新创建您的 UI 要求并在工具 -> 时间分析器中运行它。这是代码:

| specArray widgets view layout |
" Configure the Spec models "
specArray := OrderedCollection new: 81 * 2.
1 to: 81 do: [ : index | specArray
add: ('textInput' , index asString) asSymbol;
add: #TextInputFieldModel ].
view := DynamicComposableModel new
instantiateModels: specArray;
extent: 300@800;
title: 'Title'
yourself.
" Configure the Spec layout "
widgets := specArray reject: [ : ti | ti = #TextInputFieldModel ].
layout := SpecLayout composed
newColumn: [ : r |
widgets doWithIndex: [ : ti : index | r add: ti ] ];
yourself.
" Set up the widgets "
widgets doWithIndex: [ : each : index | (view perform: each) text: index asString ].
" Open the Window "
(view openWithSpecLayout: layout) delete.

正如您在屏幕截图中看到的,大部分时间都花在 TextInputFieldModel>>defaultEntryCompletion 上,因此您可以尝试加快该部分的速度(不幸的是,该方法未记录)

enter image description here

如果您应用 Leandro 的建议,您可以加快从
  • 3902 个计数,3912 毫秒。
  • 3916 个计数,3927 毫秒。


  • 1985 年计数,1988 毫秒。

  • TextInputFieldModel>>defaultEntryCompletion 中的代码是:
    defaultEntryCompletion

    | applicants |
    applicants := (Array streamContents: [:strm |
    Smalltalk globals keysDo: [ : each | (each notEmpty and: [each first canBeGlobalVarInitial])
    ifTrue: [ strm nextPut: each ] ] ]) sort.

    ^ EntryCompletion new
    dataSourceBlock: [:currText | applicants];
    filterBlock: [:currApplicant :currText | currText size > 3
    and: [currApplicant asUppercase includesSubstring: currText asString asUppercase]].

    关于user-interface - 加速 ComposableModel 新 openWithSpec(在 Pharo v3 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27758736/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com