Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use operator # instead of string.len #8751

Merged
merged 1 commit into from
Feb 1, 2023

Conversation

ronething
Copy link
Contributor

@ronething ronething commented Jan 31, 2023

Description

Fixes # (issue)

use operator # instead of string.len, as string.len use more cost than operator #

$ cat operator_sharp.lua      
a = "hello"
print(#a)

$ luac -l operator_sharp.lua

main <operator_sharp.lua:0,0> (7 instructions at 0x600002924080)
0+ params, 2 slots, 1 upvalue, 0 locals, 3 constants, 0 functions
	1	[1]	VARARGPREP	0
	2	[1]	SETTABUP 	0 0 1k	; _ENV "a" "hello"
	3	[2]	GETTABUP 	0 0 2	; _ENV "print"
	4	[2]	GETTABUP 	1 0 0	; _ENV "a"
	5	[2]	LEN      	1 1
	6	[2]	CALL     	0 2 1	; 1 in 0 out
	7	[2]	RETURN   	0 1 1	; 0 out

$ cat string_len.lua                                 
a = "hello"
print(string.len(a))

$ luac -l string_len.lua    

main <string_len.lua:0,0> (9 instructions at 0x600003368080)
0+ params, 3 slots, 1 upvalue, 0 locals, 5 constants, 0 functions
	1	[1]	VARARGPREP	0
	2	[1]	SETTABUP 	0 0 1k	; _ENV "a" "hello"
	3	[2]	GETTABUP 	0 0 2	; _ENV "print"
	4	[2]	GETTABUP 	1 0 3	; _ENV "string"
	5	[2]	GETFIELD 	1 1 4	; "len"
	6	[2]	GETTABUP 	2 0 0	; _ENV "a"
	7	[2]	CALL     	1 2 0	; 1 in all out
	8	[2]	CALL     	0 0 1	; all in 0 out
	9	[2]	RETURN   	0 1 1	; 0 out

refer: https://segmentfault.com/q/1010000007132888

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@ronething ronething marked this pull request as ready for review January 31, 2023 08:00
@spacewander spacewander merged commit 9e63f69 into apache:master Feb 1, 2023
@ronething ronething deleted the chore/use_sharp branch February 1, 2023 01:40
hongbinhsu added a commit to fitphp/apix that referenced this pull request Feb 3, 2023
* upstream/master:
  feat(elasticsearch-logger): support multi elasticsearch endpoints (apache#8604)
  chore: use operator # instead of string.len (apache#8751)
  chore: hi 2023 (apache#8748)
  refactor(admin): stream_routes/upstreams/protos/services/global_rules/consumer_groups/plugin_configs (apache#8661)
  feat: support send error-log to kafka brokers (apache#8693)
  chore: upgrade `casbin` to `1.41.5` (apache#8744)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants