问答详情
源自:5-1 性能优化

在update中调用addBalls函数时,if使用嵌套的方式会使性能更好吗?

像这样

if(curSeconds!==nextSeconds){

addBalls(MARGIN_LEFT+46.5*square, MARGIN_TOP, nextSeconds%10);

if(parseInt(curSeconds/10)!==parseInt(nextSeconds/10)){

addBalls(MARGIN_LEFT+39*square, MARGIN_TOP, parseInt(nextSeconds/10));

if(curMinutes%10!==nextMinutes%10){

addBalls(MARGIN_LEFT+27*square, MARGIN_TOP, curMinutes%10);

if(parseInt(curMinutes/10)!==parseInt(nextMinutes/10)){

addBalls(MARGIN_LEFT+19.5*square, MARGIN_TOP, parseInt(curMinutes/10));

if(curHours%10!==nextHours%10){

addBalls(MARGIN_LEFT+7.5*square, MARGIN_TOP, curHours%10);

if(parseInt(curHours/10)!==parseInt(nextHours/10)){

addBalls(MARGIN_LEFT, MARGIN_TOP, parseInt(curHours/10));

}

}

}

}

}

curTimeSeconds=nextTimeSeconds;

}


提问者:qq_感谢永远有歌把心境道破_03171663 2016-12-07 00:19

个回答

  • qq_感谢永远有歌把心境道破_03171663
    2016-12-07 00:20:05

    if(curSeconds!==nextSeconds){
    		addBalls(MARGIN_LEFT+46.5*square, MARGIN_TOP, nextSeconds%10);
    		if(parseInt(curSeconds/10)!==parseInt(nextSeconds/10)){
    			addBalls(MARGIN_LEFT+39*square, MARGIN_TOP, parseInt(nextSeconds/10));
    			if(curMinutes%10!==nextMinutes%10){
    				addBalls(MARGIN_LEFT+27*square, MARGIN_TOP, curMinutes%10);
    				if(parseInt(curMinutes/10)!==parseInt(nextMinutes/10)){
    					addBalls(MARGIN_LEFT+19.5*square, MARGIN_TOP, parseInt(curMinutes/10));
    					if(curHours%10!==nextHours%10){
    						addBalls(MARGIN_LEFT+7.5*square, MARGIN_TOP, curHours%10);
    						if(parseInt(curHours/10)!==parseInt(nextHours/10)){
    							addBalls(MARGIN_LEFT, MARGIN_TOP, parseInt(curHours/10));
    						}
    					}
    				}
    			}
    		}
    		curTimeSeconds=nextTimeSeconds;
    	}