2015-01-03 2 views
4

사용자가 하나의 단일 번호 (게임 보드 임)를 입력 할 수있는 81 개의 상자가있는 GUI가 필요했습니다.ComposableModel의 속도 향상 새로운 openWithSpec (Pharo v3)

그래서 새 TextInputFieldModel 인스턴스로 초기화하는 81 개의 인스턴스 변수를 사용하여 ComposableModel을 서브 클래 싱했습니다.

문제는 열 때 약 6 초가 걸립니다. 왜 81 개의 텍스트 상자를 열려면 시간이 오래 걸리나요? 내가 여는 것을 빠르게하기 위해 할 수있는 것이 있습니까?

답변

4

이 경우 프로파일 러를 사용할 수 있습니다. 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: [email protected]; 
     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 (불행히도 방법은 undocummented됩니다) 당신이 레안드로의 제안을 적용하면

당신은에서

  • 3902 탈리, 3912 밀리 속도를 높일 수 있습니다.
  • 3916 회, 3927 msec.

  • 1,985 탈리 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]]. 
+2

는 플라이급 패턴의 구현 각 | (각 notEmpty 및 : [각 첫 번째 canBeGlobalVarInitial]) ifTrue : [strm nextPut : each]]'. –

3

이 하나의 매트릭스 모프와 하나의 텍스트 필드 모프를 가지고있다 다루는 전통적인 방법. 행렬은 텍스트 필드를 올바른 위치에두고 텍스트 필드가 업데이트되었는지 확인하고 포커스가없는 필드의 텍스트를 그리는 역할을합니다. `블록 '으로 다시 작성할 수 있습니다 스몰 토크 전역이 keysDo : : :

은 그것은 그것은`streamContents의 내용과 같은