Skip to content
This repository has been archived by the owner on Oct 12, 2018. It is now read-only.

Inefficiency in FakeSMCDevice::getKey #61

Closed
RehabMan opened this issue Mar 8, 2013 · 1 comment
Closed

Inefficiency in FakeSMCDevice::getKey #61

RehabMan opened this issue Mar 8, 2013 · 1 comment

Comments

@RehabMan
Copy link
Collaborator

RehabMan commented Mar 8, 2013

Just something I noticed while merging in some of your recent changes. You are using snprintf inside the loop to space-pad the passed in 'name' to getKey:

   while ((key = OSDynamicCast(FakeSMCKey, iterator->getNextObject()))) {

            // Made the key name valid (4 char long): add trailing spaces if needed
            char validKeyNameBuffer[5];
            snprintf(validKeyNameBuffer, 5, "%-4s", name);

            ...

Since 'name' is invariant, the creation of validKeyNameBuffer can be moved outside the loop for efficiency:

   // Made the key name valid (4 char long): add trailing spaces if needed
   char validKeyNameBuffer[5];
   snprintf(validKeyNameBuffer, 5, "%-4s", name);

   while ((key = OSDynamicCast(FakeSMCKey, iterator->getNextObject()))) {

             ...

@CozmoNate
Copy link
Owner

Yes, thank you, fixed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants