-
Notifications
You must be signed in to change notification settings - Fork 0
[opt] 优化 ek_list.h 中api #16
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,9 +51,9 @@ struct ek_list_node_t | |
| * @param pos 当前节点指针(迭代变量) | ||
| * @param head 链表头节点 | ||
| * | ||
| * @warning 遍历过程中不能删除当前节点,否则使用 ek_list_iterate_safe | ||
| * @warning 遍历过程中不能删除当前节点,否则使用 ek_list_foreach_safe | ||
| */ | ||
| #define ek_list_iterate(pos, head) \ | ||
| #define ek_list_foreach(pos, head) \ | ||
| for (pos = (head)->next; pos != (head); pos = pos->next) | ||
|
|
||
| /** | ||
|
|
@@ -62,7 +62,7 @@ struct ek_list_node_t | |
| * @param n 临时节点指针(保存下一个节点) | ||
| * @param head 链表头节点 | ||
| */ | ||
| #define ek_list_iterate_safe(pos, n, head) \ | ||
| #define ek_list_foreach_safe(pos, n, head) \ | ||
| for (pos = (head)->next, n = pos->next; pos != (head); pos = n, n = pos->next) | ||
|
|
||
| /* clang-format on */ | ||
|
|
@@ -85,7 +85,7 @@ __EK_STATIC_INLINE void ek_list_init(ek_list_node_t *head) | |
| * @param prev 前一个节点(插入位置之前) | ||
| * @param next 后一个节点(插入位置之后) | ||
| */ | ||
| __EK_STATIC_INLINE void __ek_list_add(ek_list_node_t *new_node, ek_list_node_t *prev, ek_list_node_t *next) | ||
| __EK_STATIC_INLINE void _ek_list_insert(ek_list_node_t *new_node, ek_list_node_t *prev, ek_list_node_t *next) | ||
| { | ||
| prev->next = new_node; | ||
| new_node->next = next; | ||
|
|
@@ -98,27 +98,27 @@ __EK_STATIC_INLINE void __ek_list_add(ek_list_node_t *new_node, ek_list_node_t * | |
| * @param head 链表头节点指针 | ||
| * @param new_node 要添加的新节点 | ||
| */ | ||
| __EK_STATIC_INLINE void ek_list_add_head(ek_list_node_t *head, ek_list_node_t *new_node) | ||
| __EK_STATIC_INLINE void ek_list_insert_head(ek_list_node_t *head, ek_list_node_t *new_node) | ||
| { | ||
| __ek_list_add(new_node, head, head->next); | ||
| _ek_list_insert(new_node, head, head->next); | ||
| } | ||
|
|
||
| /** | ||
| * @brief 在链表尾部添加节点 | ||
| * @param head 链表头节点指针 | ||
| * @param new_node 要添加的新节点 | ||
| */ | ||
| __EK_STATIC_INLINE void ek_list_add_tail(ek_list_node_t *head, ek_list_node_t *new_node) | ||
| __EK_STATIC_INLINE void ek_list_insert_tail(ek_list_node_t *head, ek_list_node_t *new_node) | ||
| { | ||
| __ek_list_add(new_node, head->prev, head); | ||
| _ek_list_insert(new_node, head->prev, head); | ||
| } | ||
|
|
||
| /** | ||
| * @brief 内部函数:断开两个节点之间的连接 | ||
| * @param prev 前一个节点 | ||
| * @param next 后一个节点 | ||
| */ | ||
| __EK_STATIC_INLINE void __ek_list_remove(ek_list_node_t *prev, ek_list_node_t *next) | ||
| __EK_STATIC_INLINE void _ek_list_remove(ek_list_node_t *prev, ek_list_node_t *next) | ||
| { | ||
| next->prev = prev; | ||
| prev->next = next; | ||
|
|
@@ -132,7 +132,7 @@ __EK_STATIC_INLINE void __ek_list_remove(ek_list_node_t *prev, ek_list_node_t *n | |
| */ | ||
| __EK_STATIC_INLINE void ek_list_remove(ek_list_node_t *remove) | ||
| { | ||
| __ek_list_remove(remove->prev, remove->next); | ||
| _ek_list_remove(remove->prev, remove->next); | ||
| remove->prev = NULL; | ||
| remove->next = NULL; | ||
| } | ||
|
|
@@ -143,7 +143,7 @@ __EK_STATIC_INLINE void ek_list_remove(ek_list_node_t *remove) | |
| * @return true 链表为空 | ||
| * @return false 链表非空 | ||
| */ | ||
| __EK_STATIC_INLINE bool ek_list_empty(ek_list_node_t *head) | ||
| __EK_STATIC_INLINE bool ek_list_is_empty(ek_list_node_t *head) | ||
| { | ||
| return head->next == head; | ||
| } | ||
|
Comment on lines
+146
to
149
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ek_list_iterate/ek_list_iterate_safe被直接改名为ek_list_foreach/ek_list_foreach_safe,旧宏在头文件中不再提供,会导致任何依赖旧 API 的外部代码直接编译失败。建议至少保留旧名字作为兼容别名(可加弃用标记/注释),或在版本/变更说明中明确这是破坏性变更。