Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 优化大开关语句-AS3_Actionscript 3_Optimization_Switch Statement - Fatal编程技术网

Actionscript 3 优化大开关语句-AS3

Actionscript 3 优化大开关语句-AS3,actionscript-3,optimization,switch-statement,Actionscript 3,Optimization,Switch Statement,我有一个非常大的switch语句来处理来自服务器的套接字消息。它目前有100多个病例,并将随着时间的推移继续增长。我觉得我应该做一些比switch语句更优化的事情 我的想法是: 拥有大量函数回调。然后我可以做一些简单的事情,比如 myArrayOfCallbacks[switchValue](parameters); 这应该把O(n)中的n是开关箱的数量变成常数时间,对吗?我认为这将是一个非常好的优化 对其他方法有任何意见或建议吗?因为您要对一个值调用开关大小写,所以最好将可能的值排列到可能值

我有一个非常大的switch语句来处理来自服务器的套接字消息。它目前有100多个病例,并将随着时间的推移继续增长。我觉得我应该做一些比switch语句更优化的事情

我的想法是: 拥有大量函数回调。然后我可以做一些简单的事情,比如

myArrayOfCallbacks[switchValue](parameters);
这应该把O(n)中的n是开关箱的数量变成常数时间,对吗?我认为这将是一个非常好的优化


对其他方法有任何意见或建议吗?

因为您要对一个值调用开关大小写,所以最好将可能的值排列到可能值的静态数组中,然后获得另一个要调用的对应函数的静态数组。那么你喜欢这样:

public static const possibleValues:Array=['one value','two value',...];
// in case of ints, use only the second array
public static const callbacks:Array=[oneFunction,twoFunction,...];
// make sure functions are uniform on parameters! You can use 1 parameter "message" as is
...
var swtichValue=message.type; // "message" is an Object representing the message
// with all its contents
var callbackIndex:int=possibleValues.indexOf(switchValue);
if (callbackIndex>=0) if (callbacks[callbackIndex]) callbacks[callbackIndex](message);

是的,你的猜测是非常正确的。

因为你在一个值上调用一个switch case,你最好把可能的值排列成一个可能值的静态数组,然后得到另一个要调用的对应函数的静态数组。那么你喜欢这样:

public static const possibleValues:Array=['one value','two value',...];
// in case of ints, use only the second array
public static const callbacks:Array=[oneFunction,twoFunction,...];
// make sure functions are uniform on parameters! You can use 1 parameter "message" as is
...
var swtichValue=message.type; // "message" is an Object representing the message
// with all its contents
var callbackIndex:int=possibleValues.indexOf(switchValue);
if (callbackIndex>=0) if (callbacks[callbackIndex]) callbacks[callbackIndex](message);

是的,你的猜测是非常正确的。

因为你在一个值上调用一个switch case,你最好把可能的值排列成一个可能值的静态数组,然后得到另一个要调用的对应函数的静态数组。那么你喜欢这样:

public static const possibleValues:Array=['one value','two value',...];
// in case of ints, use only the second array
public static const callbacks:Array=[oneFunction,twoFunction,...];
// make sure functions are uniform on parameters! You can use 1 parameter "message" as is
...
var swtichValue=message.type; // "message" is an Object representing the message
// with all its contents
var callbackIndex:int=possibleValues.indexOf(switchValue);
if (callbackIndex>=0) if (callbacks[callbackIndex]) callbacks[callbackIndex](message);

是的,你的猜测是非常正确的。

因为你在一个值上调用一个switch case,你最好把可能的值排列成一个可能值的静态数组,然后得到另一个要调用的对应函数的静态数组。那么你喜欢这样:

public static const possibleValues:Array=['one value','two value',...];
// in case of ints, use only the second array
public static const callbacks:Array=[oneFunction,twoFunction,...];
// make sure functions are uniform on parameters! You can use 1 parameter "message" as is
...
var swtichValue=message.type; // "message" is an Object representing the message
// with all its contents
var callbackIndex:int=possibleValues.indexOf(switchValue);
if (callbackIndex>=0) if (callbacks[callbackIndex]) callbacks[callbackIndex](message);

所以,是的,你的猜测是非常正确的。

我会选择后端附带的客户机实现。这样你就可以不用收藏了

if (eventType in responseController) {
    //Before call, you could do secure checks, fallbacks, logging, etc.
    responseController[eventType](data);
}

//Where eventType is 'method' name, 
//for example command from the socket server is 'auth',
//if you have implemented method `auth` in your responseController
//it will be called

我将使用后端附带的客户机实现。这样你就可以不用收藏了

if (eventType in responseController) {
    //Before call, you could do secure checks, fallbacks, logging, etc.
    responseController[eventType](data);
}

//Where eventType is 'method' name, 
//for example command from the socket server is 'auth',
//if you have implemented method `auth` in your responseController
//it will be called

我将使用后端附带的客户机实现。这样你就可以不用收藏了

if (eventType in responseController) {
    //Before call, you could do secure checks, fallbacks, logging, etc.
    responseController[eventType](data);
}

//Where eventType is 'method' name, 
//for example command from the socket server is 'auth',
//if you have implemented method `auth` in your responseController
//it will be called

我将使用后端附带的客户机实现。这样你就可以不用收藏了

if (eventType in responseController) {
    //Before call, you could do secure checks, fallbacks, logging, etc.
    responseController[eventType](data);
}

//Where eventType is 'method' name, 
//for example command from the socket server is 'auth',
//if you have implemented method `auth` in your responseController
//it will be called
是的,在可能的情况下,我总是使用开关值作为键而不是开关块的映射(对象或字典)。在我看来,这种方法更具可读性。是的,在可能的情况下,我总是使用开关值作为键而不是开关块的映射(对象或字典)。在我看来,这种方法更具可读性。是的,在可能的情况下,我总是使用开关值作为键而不是开关块的映射(对象或字典)。在我看来,这种方法更具可读性。是的,在可能的情况下,我总是使用开关值作为键而不是开关块的映射(对象或字典)。在我看来,这种方法更具可读性。