Browse Source

Inspector operates on list of associations.

Dictionary implementation is quadratic,
and what is inspected is in fact list of associations.
Herby Vojčík 4 years ago
parent
commit
b57f0e686d
2 changed files with 83 additions and 36 deletions
  1. 68 28
      src/IDE.js
  2. 15 8
      src/IDE.st

+ 68 - 28
src/IDE.js

@@ -6675,17 +6675,17 @@ selector: "dive",
 protocol: "actions",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "dive\x0a\x09(self variables at: self selectedVariable) inspect",
+source: "dive\x0a\x09self selectedVariableValue inspect",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["inspect", "at:", "variables", "selectedVariable"]
+messageSends: ["inspect", "selectedVariableValue"]
 }, function ($methodClass){ return function (){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-$recv($recv($self._variables())._at_($self._selectedVariable()))._inspect();
+$recv($self._selectedVariableValue())._inspect();
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"dive",{})});
@@ -7129,6 +7129,37 @@ return self;
 }; }),
 $globals.IDEInspector);
 
+$core.addMethod(
+$core.method({
+selector: "selectedVariableValue",
+protocol: "accessing",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "selectedVariableValue\x0a\x09^ (self variables detect: [ :each | each key = self selectedVariable ]) value",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["value", "detect:", "variables", "=", "key", "selectedVariable"]
+}, function ($methodClass){ return function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv($recv($self._variables())._detect_((function(each){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return $recv($recv(each)._key()).__eq($self._selectedVariable());
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
+//>>excludeEnd("ctx");
+})))._value();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"selectedVariableValue",{})});
+//>>excludeEnd("ctx");
+}; }),
+$globals.IDEInspector);
+
 $core.addMethod(
 $core.method({
 selector: "setLabel:",
@@ -7154,16 +7185,25 @@ selector: "setVariables:",
 protocol: "accessing",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aCollection"],
-source: "setVariables: aCollection\x0a\x09variables := aCollection",
+source: "setVariables: aCollection\x0a\x09variables := \x0a\x09\x09(aCollection respondsTo: #associations)\x0a\x09\x09\x09ifTrue: [ aCollection associations ]\x0a\x09\x09\x09ifFalse: [ aCollection ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: []
+messageSends: ["ifTrue:ifFalse:", "respondsTo:", "associations"]
 }, function ($methodClass){ return function (aCollection){
 var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+if($core.assert($recv(aCollection)._respondsTo_("associations"))){
+$self.variables=$recv(aCollection)._associations();
+} else {
 $self.variables=aCollection;
+}
 return self;
-
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"setVariables:",{aCollection:aCollection})});
+//>>excludeEnd("ctx");
 }; }),
 $globals.IDEInspector);
 
@@ -7191,21 +7231,17 @@ selector: "updateButtons",
 protocol: "updating",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "updateButtons\x0a\x09(self selectedVariable notNil and: [ (self variables at: self selectedVariable) notNil ])\x0a\x09\x09ifFalse: [ diveButton at: 'disabled' put: true ]\x0a\x09\x09ifTrue: [ diveButton removeAt: 'disabled' ]",
+source: "updateButtons\x0a\x09(self selectedVariable notNil and: [ self selectedVariableValue notNil ])\x0a\x09\x09ifFalse: [ diveButton at: 'disabled' put: true ]\x0a\x09\x09ifTrue: [ diveButton removeAt: 'disabled' ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["ifFalse:ifTrue:", "and:", "notNil", "selectedVariable", "at:", "variables", "at:put:", "removeAt:"]
+messageSends: ["ifFalse:ifTrue:", "and:", "notNil", "selectedVariable", "selectedVariableValue", "at:put:", "removeAt:"]
 }, function ($methodClass){ return function (){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-if($core.assert($recv([$recv([$self._selectedVariable()
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-,$ctx1.sendIdx["selectedVariable"]=1
-//>>excludeEnd("ctx");
-][0])._notNil()
+if($core.assert($recv([$recv($self._selectedVariable())._notNil()
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 ,$ctx1.sendIdx["notNil"]=1
 //>>excludeEnd("ctx");
@@ -7213,7 +7249,7 @@ if($core.assert($recv([$recv([$self._selectedVariable()
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
-return $recv($recv($self._variables())._at_($self._selectedVariable()))._notNil();
+return $recv($self._selectedVariableValue())._notNil();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
 //>>excludeEnd("ctx");
@@ -7235,11 +7271,11 @@ selector: "updateValueTextarea",
 protocol: "updating",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "updateValueTextarea\x0a\x09valueTextarea asJQuery val: (self selectedVariable isNil\x0a\x09\x09ifTrue: [ '' ]\x0a\x09\x09ifFalse: [ (self variables at: self selectedVariable) printString ])",
+source: "updateValueTextarea\x0a\x09valueTextarea asJQuery val: (self selectedVariable isNil\x0a\x09\x09ifTrue: [ '' ]\x0a\x09\x09ifFalse: [ self selectedVariableValue printString ])",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["val:", "asJQuery", "ifTrue:ifFalse:", "isNil", "selectedVariable", "printString", "at:", "variables"]
+messageSends: ["val:", "asJQuery", "ifTrue:ifFalse:", "isNil", "selectedVariable", "printString", "selectedVariableValue"]
 }, function ($methodClass){ return function (){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -7247,14 +7283,10 @@ return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
 var $1,$2;
 $1=$recv($self.valueTextarea)._asJQuery();
-if($core.assert($recv([$self._selectedVariable()
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-,$ctx1.sendIdx["selectedVariable"]=1
-//>>excludeEnd("ctx");
-][0])._isNil())){
+if($core.assert($recv($self._selectedVariable())._isNil())){
 $2="";
 } else {
-$2=$recv($recv($self._variables())._at_($self._selectedVariable()))._printString();
+$2=$recv($self._selectedVariableValue())._printString();
 }
 $recv($1)._val_($2);
 return self;
@@ -7270,11 +7302,11 @@ selector: "updateVariablesList",
 protocol: "updating",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "updateVariablesList\x0a\x09variablesList contents: [ :html |\x0a\x09\x09self variables keysDo: [ :each || li |\x0a\x09\x09\x09li := html li.\x0a\x09\x09\x09li\x0a\x09\x09\x09\x09with: each;\x0a\x09\x09\x09\x09onClick: [ self selectVariable: each ].\x0a\x09\x09\x09self selectedVariable = each ifTrue: [\x0a\x09\x09\x09\x09li class: 'selected' ]] ]",
+source: "updateVariablesList\x0a\x09variablesList contents: [ :html |\x0a\x09\x09self variables do: [ :each || li |\x0a\x09\x09\x09li := html li.\x0a\x09\x09\x09li\x0a\x09\x09\x09\x09with: each key;\x0a\x09\x09\x09\x09onClick: [ self selectVariable: each key ].\x0a\x09\x09\x09self selectedVariable = each key ifTrue: [\x0a\x09\x09\x09\x09li class: 'selected' ]] ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["contents:", "keysDo:", "variables", "li", "with:", "onClick:", "selectVariable:", "ifTrue:", "=", "selectedVariable", "class:"]
+messageSends: ["contents:", "do:", "variables", "li", "with:", "key", "onClick:", "selectVariable:", "ifTrue:", "=", "selectedVariable", "class:"]
 }, function ($methodClass){ return function (){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -7285,24 +7317,32 @@ $recv($self.variablesList)._contents_((function(html){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
-return $recv($self._variables())._keysDo_((function(each){
+return $recv($self._variables())._do_((function(each){
 var li;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx3) {
 //>>excludeEnd("ctx");
 li=$recv(html)._li();
 $1=li;
-$recv($1)._with_(each);
+$recv($1)._with_([$recv(each)._key()
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx3.sendIdx["key"]=1
+//>>excludeEnd("ctx");
+][0]);
 $recv($1)._onClick_((function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx4) {
 //>>excludeEnd("ctx");
-return $self._selectVariable_(each);
+return $self._selectVariable_([$recv(each)._key()
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx4.sendIdx["key"]=2
+//>>excludeEnd("ctx");
+][0]);
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx4) {$ctx4.fillBlock({},$ctx3,3)});
 //>>excludeEnd("ctx");
 }));
-if($core.assert($recv($self._selectedVariable()).__eq(each))){
+if($core.assert($recv($self._selectedVariable()).__eq($recv(each)._key()))){
 return $recv(li)._class_("selected");
 }
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);

+ 15 - 8
src/IDE.st

@@ -1461,12 +1461,19 @@ selectedVariable: aString
 	selectedVariable := aString
 !
 
+selectedVariableValue
+	^ (self variables detect: [ :each | each key = self selectedVariable ]) value
+!
+
 setLabel: aString
 	label := aString
 !
 
 setVariables: aCollection
-	variables := aCollection
+	variables := 
+		(aCollection respondsTo: #associations)
+			ifTrue: [ aCollection associations ]
+			ifFalse: [ aCollection ]
 !
 
 sourceArea
@@ -1480,7 +1487,7 @@ variables
 !IDEInspector methodsFor: 'actions'!
 
 dive
-	(self variables at: self selectedVariable) inspect
+	self selectedVariableValue inspect
 !
 
 inspect: anObject
@@ -1566,7 +1573,7 @@ selectVariable: aString
 !
 
 updateButtons
-	(self selectedVariable notNil and: [ (self variables at: self selectedVariable) notNil ])
+	(self selectedVariable notNil and: [ self selectedVariableValue notNil ])
 		ifFalse: [ diveButton at: 'disabled' put: true ]
 		ifTrue: [ diveButton removeAt: 'disabled' ]
 !
@@ -1574,17 +1581,17 @@ updateButtons
 updateValueTextarea
 	valueTextarea asJQuery val: (self selectedVariable isNil
 		ifTrue: [ '' ]
-		ifFalse: [ (self variables at: self selectedVariable) printString ])
+		ifFalse: [ self selectedVariableValue printString ])
 !
 
 updateVariablesList
 	variablesList contents: [ :html |
-		self variables keysDo: [ :each || li |
+		self variables do: [ :each || li |
 			li := html li.
 			li
-				with: each;
-				onClick: [ self selectVariable: each ].
-			self selectedVariable = each ifTrue: [
+				with: each key;
+				onClick: [ self selectVariable: each key ].
+			self selectedVariable = each key ifTrue: [
 				li class: 'selected' ]] ]
 ! !