luat_rostr.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "luat_base.h"
  2. #include "luat_rostr.h"
  3. #include "lstring.h"
  4. #include "lgc.h"
  5. #define LUAT_LOG_TAG "rostr"
  6. #include "luat_log.h"
  7. extern const luat_rostr_short_t rostr_shr_len0;
  8. extern const luat_rostr_short_t rostr_shr_len1[];
  9. extern const luat_rostr_short44_t rostr_shr_datas[];
  10. GCObject* luat_rostr_get_gc(const char *val_str, size_t len) {
  11. if (len == 0) {
  12. // LLOGD("返回空字符串的rostr指针");
  13. return (GCObject*)&rostr_shr_len0;
  14. }
  15. if (len == 1) {
  16. const uint8_t* tmp = (const uint8_t*)val_str;
  17. return (GCObject*)&rostr_shr_len1[tmp[0]];
  18. }
  19. const luat_rostr_short44_t* ptr = rostr_shr_datas;
  20. while (ptr->str.shrlen) {
  21. if (ptr->str.shrlen == len && strncmp(val_str, ptr->data, len) == 0) {
  22. // LLOGD("返回rostr指针 %p %s", ptr, ptr->data);
  23. return (GCObject*)ptr;
  24. }
  25. ptr++;
  26. }
  27. return NULL;
  28. }
  29. TString* luat_rostr_get(const char *val_str, size_t len) {
  30. GCObject* gc = luat_rostr_get_gc(val_str, len);
  31. if (gc == NULL) {
  32. return NULL;
  33. }
  34. return gco2ts(gc);
  35. }