lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



You should be using luaL_checklstring() here. You can pass a pointer _and_
the length to the StringPiece constructor:

	size_t n;
	const char *p = luaL_checklstring(L, 2, &n);
	StringPiece subject(p, (int)n);
...

Thank you for catching this! I did not realize the significance of this until resting a bit and reviewing this with a fresh pair of eyes.

Now I feel like an idiot -- in hindsight I should have realized this was the problem. I even looked at stringpiece.h at one point and saw that the constructor for StringPiece(const char *) *uses strlen* to determine the length of the string. But alas, I didn't make the mental connection sooner that this linear time operation was the root cause of the performance impact -- I should have though.

Fixing this silly oversight mitigates the overhead I was seeing. Thanks again and sorry for the noise!