Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6363635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:03:45+00:00 2026-05-25T00:03:45+00:00

target_results is a NSMutableDictionary. Is this an efficient way to store partial sums into

  • 0

target_results is a NSMutableDictionary. Is this an efficient way to store partial sums into a list? Can you suggest any improvement?

NSInteger temp_key = [rs intForColumn:@"some_int_field"];
NSInteger existing_value = [[target_results objectForKey:[NSNumber numberWithInteger:temp_key]] intValue];

if (existing_value > 0)
{
    //add to existing
    [target_results setObject:[NSNumber numberWithInteger:10+existing_value] forKey:[NSNumber numberWithInteger:temp_key]];
}
else
{
     //new entry
[target_results setObject:[NSNumber numberWithInteger:10] forKey:[NSNumber numberWithInteger:temp_key]];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:03:46+00:00Added an answer on May 25, 2026 at 12:03 am

    The most correct way to optimise is to profile and find where the actual bottlenecks are, if any. That said, working from first principles…

    Firstly, there’s no need to call NSNumber twice (three times in the code, twice at runtime). Each call creates a new object, so there’s a memory allocation overhead to that. So that’s a cut to:

    NSInteger temp_key_int = [rs intForColumn:@"some_int_field"];
    NSNumber *temp_key = [NSNumber numberWithInteger:temp_key_int];
    
    NSInteger existing_value = [[target_results objectForKey:temp_key] intValue];
    
    if (existing_value > 0)
    {
        //add to existing
        [target_results setObject:[NSNumber numberWithInteger:10+existing_value] forKey:temp_key];
    }
    else
    {
         //new entry
    [target_results setObject:[NSNumber numberWithInteger:10] forKey:temp_key];
    }
    

    The if statement also doesn’t seem to achieve anything. So you could further reduce the code to:

    NSInteger temp_key_int = [rs intForColumn:@"some_int_field"];
    NSNumber *temp_key = [NSNumber numberWithInteger:temp_key_int];
    
    // will create a new entry or replace an existing entry, as per the normal behaviour
    // of NSMutableDictionary
    NSInteger existing_value = [[target_results objectForKey:temp_key] intValue];
    [target_results setObject:[NSNumber numberWithInteger:10+existing_value] forKey:temp_key];
    

    I seriously doubt you’ll see any performance issues with that or with the original code. However, you describe your data structure as a list, so you might consider using an NSMutableArray rather than a dictionary, assuming you can place an initialisation step.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am trying to store the result from a render target into an
setTimeout(target.mousedown, 200) doesn't seem to work. I can do setTimeout(target.mousedown(), 200) , but this
This is my first time setting up teamcity and I am running into some
I'm trying to loop results from a php script into my jquery friends list.
I get this error: You can't specify target table 'wp_mail_queue' for update in FROM
(The target browser is IE8) I have a div that contains a list of
I have an applications that I've built to target SDK 3.0. In this application
I'm using Delphi 7 and can't predict the target version of Windows. I need
I am sure the title is not even right on this one. Here is
What can I do if I want the browser to remember search results requested

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.