style cleanup of HVIF vars; make popcount work in gcc2; popcount will be removed once we access BNetworkAddress directly instead of through fSettings

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40355 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Alexander von Gluck IV
2011-02-04 17:46:59 +00:00
parent 6f0278cdc9
commit 56b0a41b70
2 changed files with 41 additions and 21 deletions
@@ -58,7 +58,7 @@ our_image(image_info& image)
int int
netmaskbitcount(const char* buf) netmaskbitcount(const char* buf)
{ {
return(__builtin_popcount(inet_addr(buf))); return(PopCount(inet_addr(buf)));
} }
@@ -233,10 +233,10 @@ InterfaceListItem::_Init()
void void
InterfaceListItem::_PopulateBitmaps(const char* mediaType) { InterfaceListItem::_PopulateBitmaps(const char* mediaType) {
const uint8* HVIFInterfaceIcon; const uint8* interfaceHVIF;
const uint8* HVIFOffline; const uint8* offlineHVIF;
const uint8* HVIFPending; const uint8* pendingHVIF;
const uint8* HVIFOnline; const uint8* onlineHVIF;
BBitmap* interfaceBitmap = NULL; BBitmap* interfaceBitmap = NULL;
@@ -257,22 +257,22 @@ InterfaceListItem::_PopulateBitmaps(const char* mediaType) {
size_t iconSize; size_t iconSize;
// Try specific interface icon? // Try specific interface icon?
HVIFInterfaceIcon = (const uint8*)addonResources.LoadResource( interfaceHVIF = (const uint8*)addonResources.LoadResource(
B_VECTOR_ICON_TYPE, Name(), &iconSize); B_VECTOR_ICON_TYPE, Name(), &iconSize);
if (HVIFInterfaceIcon == NULL && mediaType != NULL) if (interfaceHVIF == NULL && mediaType != NULL)
// Not found, try interface media type? // Not found, try interface media type?
HVIFInterfaceIcon = (const uint8*)addonResources.LoadResource( interfaceHVIF = (const uint8*)addonResources.LoadResource(
B_VECTOR_ICON_TYPE, mediaType, &iconSize); B_VECTOR_ICON_TYPE, mediaType, &iconSize);
if (HVIFInterfaceIcon == NULL) if (interfaceHVIF == NULL)
// Not found, try default interface icon? // Not found, try default interface icon?
HVIFInterfaceIcon = (const uint8*)addonResources.LoadResource( interfaceHVIF = (const uint8*)addonResources.LoadResource(
B_VECTOR_ICON_TYPE, "ether", &iconSize); B_VECTOR_ICON_TYPE, "ether", &iconSize);
if (HVIFInterfaceIcon) { if (interfaceHVIF) {
// Now build the bitmap // Now build the bitmap
interfaceBitmap = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32); interfaceBitmap = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
if (BIconUtils::GetVectorIcon(HVIFInterfaceIcon, if (BIconUtils::GetVectorIcon(interfaceHVIF,
iconSize, interfaceBitmap) == B_OK) iconSize, interfaceBitmap) == B_OK)
fIcon = interfaceBitmap; fIcon = interfaceBitmap;
else else
@@ -280,28 +280,28 @@ InterfaceListItem::_PopulateBitmaps(const char* mediaType) {
} }
// Load possible state icons // Load possible state icons
HVIFOffline = (const uint8*)addonResources.LoadResource( offlineHVIF = (const uint8*)addonResources.LoadResource(
B_VECTOR_ICON_TYPE, "offline", &iconSize); B_VECTOR_ICON_TYPE, "offline", &iconSize);
if (HVIFOffline) { if (offlineHVIF) {
fIconOffline = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32); fIconOffline = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
BIconUtils::GetVectorIcon(HVIFOffline, iconSize, fIconOffline); BIconUtils::GetVectorIcon(offlineHVIF, iconSize, fIconOffline);
} }
HVIFPending = (const uint8*)addonResources.LoadResource( pendingHVIF = (const uint8*)addonResources.LoadResource(
B_VECTOR_ICON_TYPE, "pending", &iconSize); B_VECTOR_ICON_TYPE, "pending", &iconSize);
if (HVIFPending) { if (pendingHVIF) {
fIconPending = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32); fIconPending = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
BIconUtils::GetVectorIcon(HVIFPending, iconSize, fIconPending); BIconUtils::GetVectorIcon(pendingHVIF, iconSize, fIconPending);
} }
HVIFOnline = (const uint8*)addonResources.LoadResource( onlineHVIF = (const uint8*)addonResources.LoadResource(
B_VECTOR_ICON_TYPE, "online", &iconSize); B_VECTOR_ICON_TYPE, "online", &iconSize);
if (HVIFOnline) { if (onlineHVIF) {
fIconOnline = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32); fIconOnline = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
BIconUtils::GetVectorIcon(HVIFOnline, iconSize, fIconOnline); BIconUtils::GetVectorIcon(onlineHVIF, iconSize, fIconOnline);
} }
@@ -27,6 +27,26 @@
#include "Settings.h" #include "Settings.h"
/* GCC 3.4 and onward have a built-in "population count"
* feature that takes advantage of a cpu instruction
*/
// TODO : remove when access to BNetworkAddress is complete
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
# define PopCount(buffer) __builtin_popcount(buffer)
#else
/* On < GCC 3.4 we do it the old fashon way */
int PopCount(unsigned buf)
{
buf = buf - ((buf >> 1) & 0x55555555);
buf = (buf & 0x33333333) + ((buf >> 2) & 0x33333333);
buf = (buf + (buf >> 4)) & 0x0F0F0F0F;
buf = buf + (buf >> 8);
buf = buf + (buf >> 16);
return buf & 0x0000003F;
}
#endif
int netmaskbitcount(const char* buf); int netmaskbitcount(const char* buf);