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)

Deskbar_truncate_label_cleanup.diff (1.3 KB ) - added by jscipione 13 years ago.
A patch that replaces a malloc and free of a char* and a const char* with a single BString.
Deskbar_truncate_label_cleanup_2.diff (1.3 KB ) - added by jscipione 13 years ago.
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.

Download all attachments as: .zip

Change History (6)

by jscipione, 13 years ago

A patch that replaces a malloc and free of a char* and a const char* with a single BString.

comment:1 by jscipione, 13 years ago

patch: 01

by jscipione, 13 years ago

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:2 by Charlie_X, 13 years ago

Do you have tests for this?

in reply to:  2 comment:3 by jscipione, 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 pulkomandy, 13 years ago

Resolution: invalid
Status: newclosed

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...

Note: See TracTickets for help on using tickets.