What is the execute sequence of i++ in java -


what execute sequence of following code?

 if (hash[s.charat(right++)]-- >= 1) 

in understanding

 1. hash[s.charat(right)] >= 1  2. hash[s.charat(right)]--  3. right++; 

thank you!!!!

execute sequence of if (hash[s.charat(right++)]-- >= 1) is:

  1. read value of hash (a)
  2. read value of s (b)
  3. read value of right (c)
  4. increment value of right
  5. call b.charat(c) (d)
  6. read value of a[d] (e)
  7. decrement value of a[d]
  8. read constant 1 (f)
  9. skip past if block if e < f.

if hash, s, , right 3 local variables, bytecode of if statement is:

 1: aload_1  2: aload_2  3: iload_3  4: iinc          3, 1  5: invokevirtual #21                 // method java/lang/string.charat:(i)c  6: dup2     iaload  7: dup_x2     iconst_1     isub     iastore  8: iconst_1  9: if_icmplt     99 

update

the effect same as-if had written:

boolean cond = hash[s.charat(right)]; hash[s.charat(right)]--; right++; if (cond) { 

except values read once, , charat() call , index lookup happens once.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -