Opened 13 years ago
Closed 13 years ago
#7772 closed enhancement (invalid)
[Patch] Deskbar Truncate String Code Cleanup
Reported by: | jscipione | Owned by: | axeld |
---|---|---|---|
Priority: | normal | Milestone: | R1 |
Component: | Applications/Deskbar | Version: | R1/Development |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
I re-factored the Deskbar truncate label code (The code that truncates a string with an ellipses like Activi...onitor when space gets tight in horizontal mode) to use a a single BString instead of a const char* and a char* that gets malloc'ed and free'd. The code does exactly the same thing but is just a little cleaner.
Attachments (2)
Change History (6)
by , 13 years ago
Attachment: | Deskbar_truncate_label_cleanup.diff added |
---|
comment:1 by , 13 years ago
patch: | 0 → 1 |
---|
by , 13 years ago
Attachment: | Deskbar_truncate_label_cleanup_2.diff added |
---|
There is no reason to check if the label is NULL after truncating since I am using a BString which will not return NULL for a truncated string.
comment:3 by , 13 years ago
Replying to Charlie_X:
Do you have tests for this?
There is a test for BView->TruncateString() in src/tests/kits/interface/TruncateString.cpp
comment:4 by , 13 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
This is not correct :
- Creating a BString object and copying the full label to it costs more than mallocing a string. So your change makes the code slower.
- TruncateLabel does not do the same as TruncateString. It is dedicated to menus and may do complex stuff such as ensuring the result is not the same as the truncated label from another menu item in the same menu. (even if that may not be implemented yet).
While the TruncateLabel function is a bit unsafe (no control on the buffer size), we have no way to fix it without breaking binary compatibility. So this will have to wait till R2...
A patch that replaces a malloc and free of a char* and a const char* with a single BString.