Use struct string_T to store field ocn_name in struct ocmember_T.
This means we can use the .length field in struct string_T.
In addition in vim9class.c:
1: change some calls from ga_concat() to ga_concat_len() where the length is known.
2: in ex_class() remove unneeded variable name.
3. in intf_method_present() remove unneeded variable cl_name.
4: in update_member_method_lookup_table() move some assignments from inner loops into outer loops.
5: in member_lookup() remove unneeded else.
6: in is_duplicate_variable() and is_duplicate_enum() rearrange the string comparisons to first check the lengths match.
Cheers
John
https://github.com/vim/vim/pull/18973
(7 files)
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@Copilot commented on this pull request.
This PR refactors the ocmember_T struct to use string_T for the ocm_name field instead of a raw char_u* pointer. This allows the code to leverage the .length field for optimizations and cleaner comparisons.
Key Changes:
ocm_name from char_u* to string_T struct (containing .string and .length fields).string when accessing the string pointer and .length when accessing the lengthga_concat_len() instead of ga_concat() where lengths are knownis_duplicate_variable() and is_duplicate_enum() by comparing lengths before string contentname in ex_class(), cl_name in intf_method_present())update_member_method_lookup_table()else clause in member_lookup()Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file| File | Description |
|---|---|
| src/structs.h | Changed ocm_name field type from char_u* to string_T |
| src/vim9class.c | Updated all member name allocations, accesses, and comparisons to use string_T; added optimizations using length-based comparisons and ga_concat_len() |
| src/vim9expr.c | Updated member name accesses to use .string field |
| src/vim9execute.c | Updated member name accesses to use .string field |
| src/vim9compile.c | Updated member name accesses to use .string field |
| src/userfunc.c | Updated member name comparison to use .string field |
| src/eval.c | Updated member name accesses to use .string field |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
In src/vim9class.c:
> + if (m->ocm_name.string == NULL) + m->ocm_name.length = 0;
When vim_strnsave() fails and returns NULL, the function should return FAIL to indicate memory allocation failure. The function documentation states "Returns OK on success and FAIL on memory allocation failure". Currently, it sets length to 0 and continues, which leaves the member in an inconsistent state and incorrectly returns OK.
- if (m->ocm_name.string == NULL)
- m->ocm_name.length = 0;
+ if (m->ocm_name.string == NULL)
+ {
+ m->ocm_name.length = 0;
+ return FAIL;
+ }
In src/vim9class.c:
> + m->ocm_name.string = vim_strnsave(m->ocm_name.string, m->ocm_name.length); + if (m->ocm_name.string == NULL) + m->ocm_name.length = 0;
When vim_strnsave() fails and returns NULL while copying parent member names, this should be treated as a memory allocation failure. The function should return FAIL rather than setting length to 0 and continuing. Additionally, if allocation fails during member copying, previously allocated members should be cleaned up before returning FAIL.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
thanks
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()