Is using string.length() in loop efficient?

前端 未结 6 1846
我在风中等你
我在风中等你 2021-02-20 09:11

For example, assuming a string s is this:

for(int x = 0; x < s.length(); x++)

better than this?:

int length         


        
6条回答
  •  花落未央
    2021-02-20 10:01

    Is s.length() inline and returns a member variable? then no, otherwise cost of dereferencing and putting stuff in stack, you know all the overheads of function call you will incur for each iteration.

提交回复
热议问题