GithubHelp home page GithubHelp logo

the existing # operator about lua-resty-redis HOT 5 CLOSED

aCayF avatar aCayF commented on August 17, 2024
the existing # operator

from lua-resty-redis.

Comments (5)

agentzh avatar agentzh commented on August 17, 2024

@aCayF Or just use the "n" variable name. Patches welcome!

from lua-resty-redis.

agentzh avatar agentzh commented on August 17, 2024

@aCayF Okay, it seems that the "limit" condition in the loop for i = 1, limit is only evaluated once, according to the official Lua language manual:

http://www.lua.org/manual/5.1/manual.html#2.4.5

So the # operator will not be re-evaluated upon every loop iteration. So we're fine here. No patch is needed.

from lua-resty-redis.

aCayF avatar aCayF commented on August 17, 2024

if i didn't misunderstand anything, i think the overhead eliminated by the #22 is re-hashing table when using table.insert and evaluating # operator appeared in the loop block every loop iteration

from lua-resty-redis.

agentzh avatar agentzh commented on August 17, 2024

@aCayF Nah, table.insert does not always rehash the table. Its behavior is similar to tb[i] = v but it always invokes lj_tab_len on the table, which is called by the # operator too. So essentially we are saving the overhead in lj_tab_len upon every table insertion here.

In #22, the # operator is called by every loop iteration but in the limit part of the loop for i = 1, limit, it is called only once upon the loop entry.

from lua-resty-redis.

aCayF avatar aCayF commented on August 17, 2024

Thank you for the information :)

from lua-resty-redis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.