Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1680118
  • 博文数量: 1493
  • 博客积分: 38
  • 博客等级: 民兵
  • 技术积分: 5834
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-19 17:28
文章分类

全部博文(1493)

文章存档

2016年(11)

2015年(38)

2014年(137)

2013年(253)

2012年(1054)

2011年(1)

分类:

2012-05-11 08:31:14

今天查看自己为《专业嵌入式软件开发》一书所写的代码时发现,个别函数由于没有引入中间变量,使代码行既长又不易读。重构前后的代码如下所示。
 
重构前:
  1. if (TIMER_STARTED == _handle->state_) { 
  2.     timer_handle_t next; 
  3.      
  4.     if (g_timer_next == _handle) { 
  5.         g_timer_next = (timer_handle_t) dll_next (&g_bucket_firing->dll_,  
  6.             &_handle->node_); 
  7.     } 
  8.     next = (timer_handle_t)dll_next  
  9.         (&g_buckets [_handle->bucket_index_].dll_, &_handle->node_); 
  10.     if (0 != next) { 
  11.         next->round_ += _handle->round_; 
  12.     } 
  13.     dll_remove (&g_buckets [_handle->bucket_index_].dll_, &_handle->node_); 
  14.     if (g_buckets [_handle->bucket_index_].reentrance_ > 0) { 
  15.         g_bucket_firing->level_ ++; 
  16.     } 
 
重构后:
  1. if (TIMER_STARTED == _handle->state_) { 
  2.     timer_handle_t next; 
  3.     bucket_t *p_bucket = &g_buckets [_handle->bucket_index_]; 
  4.      
  5.     if (g_timer_next == _handle) { 
  6.         g_timer_next = (timer_handle_t) dll_next (&g_bucket_firing->dll_,  
  7.             &_handle->node_); 
  8.     } 
  9.     next = (timer_handle_t)dll_next (&p_bucket->dll_, &_handle->node_); 
  10.     if (0 != next) { 
  11.         next->round_ += _handle->round_; 
  12.     } 
  13.     dll_remove (&p_bucket->dll_, &_handle->node_); 
  14.     if (p_bucket->reentrance_ > 0) { 
  15.         g_bucket_firing->level_ ++; 
  16.     } 
本文出自李云的博客,请务必保留此出处:http://blog.chinaunix.net/uid-26470037-id-3203040.html。
阅读(323) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~