Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic_string.h: 各种问题 #105

Open
frederick-vs-ja opened this issue Jun 24, 2022 · 0 comments
Open

basic_string.h: 各种问题 #105

frederick-vs-ja opened this issue Jun 24, 2022 · 0 comments

Comments

@frederick-vs-ja
Copy link
Contributor

逻辑问题

  1. 目前空终止符(末尾的 \0L\0 等)的设置是惰性的。这与标准要求不合,并且可能有并发调用 const 限定函数导致数据竞争的问题;
  2. capacity() 的返回值应该是当前分配的存储中能放下的字符串元素数,元素不含末尾的空终止符(此处与 Jonathan Wakely 确认过)。所以目前实现的值多了 1
  3. 各种插入操作在需要扩容时有可能提前将旧存储释放。而标准是允许插入的范围是就是字符串原先的一部分的,这可能导致问题。

优化问题

  1. 复制赋值运算符在 rhs.size() <= this->capacity() 时不应分配新存储。
  2. operator+ 可以在一些情况不分配新存储。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant