-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Convert System.Globalization.Native to C #22378
Conversation
f3eda5e
to
f82860a
Compare
Convert u_charsToUChars_safe to ICU style error handling Unify error handling code across functions to use the same patterns Add static modifier to functions that are used only from single C file
Move SortHandle out of public API header, it is opaque structure
4fa7f35
to
772b2da
Compare
@dotnet-bot test CentOS7.1 x64 Debug Innerloop Build please |
I believe I have addressed all the original feedback and it should be ready for review. Some enum names are not perfect, but it should not be a regression compared to the previous C++ code. Error handling could likely be further refactored and improved, but again, it should not be a regression in the current state. |
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.
Looks great. Thank you!
{ | ||
return false; | ||
return FALSE; |
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.
C99 <stdbool.h>
is used in multiple places in CoreFX ref, could it be used instead to save 3 bytes per instance, per call?
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.
How does it actually save anything? In nearly all the instances it ends up in the registers which are not byte-sized anyway.
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.
I removed usage of <stdbool.h> because it was mixed with the ICU's own UBool type and TRUE/FALSE values. There was really no need to mix two or three different boolean types.
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.
Ok. true
/false
is unsigned char
(integral constant macro in smallest range) in the std header, so I always tend to use it over TRUE/FALSE in Unix (and Windows, since VS2013). :)
callback(symbolBuf.data(), context); | ||
if (symbolBuf != stackSymbolBuf) | ||
{ | ||
free(symbolBuf); |
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.
free [](start = 12, length = 4)
would it be better to use the allocated buffer through the loop and then free only once after the loop done or when you need to reallocate?
this is just suggestion but you don't need to to do it if you think this will complicate the code especially I am expecting most of the symbols will fit on the stack buffer
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.
Most, if not all, of the things really fit into the stack buffer, so I don't expect the allocation path to be hit. As such it didn't make much sense to optimize it.
CC @janvorli |
} | ||
else | ||
{ | ||
pCollator = entry->second; | ||
free(map); | ||
pCollator = (*(TCollatorMap**)entry)->UCollator; | ||
} | ||
|
||
pthread_mutex_unlock(&pSortHandle->collatorsLockObject); |
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.
It seems the free(map) should be done after the if / else so that it is freed for both code paths.
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.
The whole collatorsPerOption
in SortHandle
is unused too. I will go through the code and submit a PR to fix it. Thanks for noticing it.
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.
The tsearch
adds it as a new node to a binary tree (tfind
few lines above guarantees that's the case), so it is not a memory leak. The code unnecessarily does two lookups though. The memory is eventually reclaimed in GlobalizationNative_CloseSortHandle
.
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.
Ah, ok. Thank you for looking into it. I haven't realized the tsearch adds the new node.
Allocate initial array using malloc to avoid needlessly zeroing it Reinstate optimization for empty array returned from GetCustomRules lost in dotnet#22378
Allocate initial array using malloc to avoid needlessly zeroing it Reinstate optimization for empty array returned from GetCustomRules lost in dotnet#22378
…tions and GetCollatorFromSortHandle (#24100) * Fix allocation size calculation when resizing array Allocate initial array using malloc to avoid needlessly zeroing it Reinstate optimization for empty array returned from GetCustomRules lost in #22378 * Avoid resizing arrays in GetCustomRules by preallocating the maximum size we can consume (5648 bytes) * Avoid creating a binary search tree for something that could be easily stored as 32-entry lookup table * Remove obsolete comment
Convert System.Globalization.Native to C Commit migrated from dotnet/coreclr@a51af08
…tions and GetCollatorFromSortHandle (dotnet/coreclr#24100) * Fix allocation size calculation when resizing array Allocate initial array using malloc to avoid needlessly zeroing it Reinstate optimization for empty array returned from GetCustomRules lost in dotnet/coreclr#22378 * Avoid resizing arrays in GetCustomRules by preallocating the maximum size we can consume (5648 bytes) * Avoid creating a binary search tree for something that could be easily stored as 32-entry lookup table * Remove obsolete comment Commit migrated from dotnet/coreclr@a59ead8
Revival of #18614.
The original PR was closed and never finished. These were the remaining issues raised during the review:
I started to address them. The error handling is not always as pretty as it should be. Notably
ucal_set
doesn't handleNULL
value in first parameter, so explicit error handling must precede it.