阅读STL源码剖析之list
2024-08-27 06:58:20
首先,以我之愚见,觉得有两个地方可以优化一下,不知对否,有待商榷:
1、在list的结点定义中
template<typename T>
struct __list_node
{
typedef void* void_pointer;
void_pointer prev;
void_pointer next;
T data;
}
出现的void_pointer是否改为如下更为妥当:
template<typename T>
struct __list_node
{
typedef __list_node<T>* pointer;
pointer prev;
pointer next;
T data;
}
这样可以省略后面的大量指针转换操作(link_type与void_pointer)
2、在remove()函数的实现中:
template<class T,class Alloc>
void list<T,Alloc>::remove(const T& value)
{
iterator first=begin();
iterator last=end();
while(first!=last)
{
iterator next=first;
++next;
if(value==*first) erase(first);
first=next;
}
}
改为如下时候更简洁优化:
template<class T,class Alloc>
void list<T,Alloc>::remove(const T& value)
{
iterator first=begin();
iterator last=end();
while(first!=last)
{
first=erase(first);
}
}
最新文章
- codevs 2287 火车站
- getAttribute、setAttribute、removeAttribute
- react native RadioButton(单选按钮)
- View Controller Relationships
- Android三种播放视频的方式
- ButterKnife
- WPFFontCache_v0400.exe CPU使用率过高的问题
- 【Stage3D学习笔记续】山寨Starling(一):从事件说起
- nginx使用自认证的https证书
- Qt学习
- Paxos 实现日志复制同步(Multi-Paxos)
- RabbitMQ安装和使用(和Spring集成)
- 芝麻HTTP:Python爬虫实战之爬取糗事百科段子
- Linux多线程实践(2) --线程基本API
- MySql给表添加列和注释
- selenium+python-unittest多线程生成报告
- 欢迎来到GitHub世界
- 步步为营-30-AES加密与解密
- Java基础-SSM之mybatis的树形控件(自关联)
- miRTarBase 数据库简介
热门文章
- linux系统文件的颜色代表的意思
- HTML 页面加载动画效果
- 树莓派上搭建基于Python+web.py+fastcgi+lighttpd的网站
- Cocos2d-X 2.2嵌入MFC的子窗口
- Cocoapod错误 - Xcode6.4
- app应用程序本地化--备用
- delphi xe5 android 开发实现手机打电话和发短信
- python中的__init__ 、__new__、__call__等内置函数的剖析
- 需要插入子集的时候如何更新父级ID
- 转:在Eclipse中进行C/C++开发的配置方法(20140721最新版)