格式


/*

** Create or reuse a zero-terminated string, first checking in the

** cache (using the string address as a key). The cache can contain

** only zero-terminated strings, so it is safe to use 'strcmp' to

** check hits.

*/

TString *luaS_new (lua_State *L, const char *str) {

  unsigned int i = point2uint(str) % STRCACHE_N;  /* hash */

  int j;

  TString **p = G(L)->strcache[i];

  for (j = 0; j < STRCACHE_M; j++) {

    if (strcmp(str, getstr(p[j])) == 0)  /* hit? */

      return p[j];  /* that is it */

  }

  /* normal route */

  for (j = STRCACHE_M - 1; j > 0; j--)

    p[j] = p[j - 1];  /* move out last element */

  /* new element is first in the list */

  p[0] = luaS_newlstr(L, str, strlen(str));

  return p[0];

}

你可能感兴趣的:(格式)