Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #107422

Re: Appropriate optimization

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: Appropriate optimization
Date 2017-03-30 10:41 +1300
Message-ID <ek2o06Ft3siU1@mid.individual.net> (permalink)
References <117d90fa-6b8d-4a4f-a663-4686945fdc2d@googlegroups.com>

Show all headers | View raw


On 03/30/17 09:44 AM, Rick C. Hodgin wrote:
> This question is for anyone, but I'm specifically curious what Supercat
> thinks...
>
> Would it be an appropriate optimization to move the code on lines 101:
> and 102: to somewhere in the middle of the if..expression on line 104:
>
>            // Note:  This code is in the middle of a local function
>      101:      int count = sizeof(thing) / my_sizing_determination(thing);
>      102:      int size  = count * MY_COUNT_REQUIREMENT;
>      103:
>      104:      if (!p && (p = allocate_something(count, size)))
>      105:      {
>                    ... only the code in this block uses count and size
>      Nnn:      }
>
> The values not used before that point in the function, and they're
> not used outside of the loop, and they're not flagged as volatile.
> It would delay or prevent the call to my_sizing_determination(),
> and is that a constraint?

Why don't you just put them in the block where they belong?

-- 
Ian

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Appropriate optimization "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-03-29 13:44 -0700
  Re: Appropriate optimization Ian Collins <ian-news@hotmail.com> - 2017-03-30 10:41 +1300
    Re: Appropriate optimization supercat@casperkitty.com - 2017-03-29 15:22 -0700
  Re: Appropriate optimization supercat@casperkitty.com - 2017-03-29 15:10 -0700
    Re: Appropriate optimization Robert Wessel <robertwessel2@yahoo.com> - 2017-03-30 00:47 -0500
    Re: Appropriate optimization David Brown <david.brown@hesbynett.no> - 2017-03-30 10:15 +0200
    Re: Appropriate optimization "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-03-30 10:11 -0700
      Re: Appropriate optimization David Brown <david.brown@hesbynett.no> - 2017-03-30 19:55 +0200
      Re: Appropriate optimization supercat@casperkitty.com - 2017-03-30 11:47 -0700
        Re: Appropriate optimization Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-03-30 12:03 -0700
          Re: Appropriate optimization Keith Thompson <kst-u@mib.org> - 2017-03-30 12:24 -0700
          Re: Appropriate optimization supercat@casperkitty.com - 2017-03-30 13:21 -0700
            Re: Appropriate optimization Ike Naar <ike@iceland.freeshell.org> - 2017-03-30 20:39 +0000
              Re: Appropriate optimization supercat@casperkitty.com - 2017-03-30 13:58 -0700
  Re: Appropriate optimization David Brown <david.brown@hesbynett.no> - 2017-03-30 10:20 +0200

csiph-web