lua-users home
lua-l archive

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




On 23 April 2011 22:58, Emmanuel Oga <emmanueloga@gmail.com> wrote:
https://gist.github.com/938457#file_subsequence.c
Random notes, nothing checked or profiled.
As pointed out line 15 checks both str and subseq are not null and whilst the compiler may remove these checks they are not needed. If subseq where ever NULL then IIRC the call to strlen would be undefined.
Lua uses the same representation for strings which are the same so you could add a short cut check str == subseq. 
You could then use restrict qualifier on the char pointer which is a compiler optimisation hint.
Remove the strlen call as I believe Lua already has this information which you could retrieve via lua_tolstring, yet this would require you check for that the index is a string.

Liam