If those are the only two times, then it is "fewer lines of code" to
not use a local variable.  In many cases it makes sense (to me) to use
a local variable, but not in the example you provided.

-eric

On Wed, Jan 6, 2010 at 10:46 AM, Chris Fleizach <cfleiz...@apple.com> wrote:
> I see a lot of code that calls the same function a number of times in the 
> same scope.
>
> Is it better to store that result in a local variable, or is it better to 
> repeatedly call a method...
>
> in this example, node() is called two times
>
>    return !m_renderer->node() || !m_renderer->node()->isContentEditable();
>
> Would it better to write it as
>
>        Node* node = m_renderer->node();
>        return !node || !node->isContentEditable();
> _______________________________________________
> webkit-dev mailing list
> webkit-dev@lists.webkit.org
> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev
>
_______________________________________________
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev

Reply via email to