[webkit-dev] Better to store a local variable or call a method repeatedly?
Eric Seidel
eric at webkit.org
Wed Jan 6 10:52:02 PST 2010
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 <cfleizach at 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 at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev
>
More information about the webkit-dev
mailing list