mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Simplify "" string code
This commit is contained in:
+11
-12
@@ -4558,10 +4558,6 @@ lbValue lb_emit_clamp(lbProcedure *p, Type *t, lbValue x, lbValue min, lbValue m
|
|||||||
|
|
||||||
|
|
||||||
LLVMValueRef lb_find_or_add_entity_string_ptr(lbModule *m, String const &str) {
|
LLVMValueRef lb_find_or_add_entity_string_ptr(lbModule *m, String const &str) {
|
||||||
if (str.len == 0) {
|
|
||||||
return LLVMConstNull(lb_type(m, t_u8_ptr));
|
|
||||||
}
|
|
||||||
|
|
||||||
StringHashKey key = string_hash_string(str);
|
StringHashKey key = string_hash_string(str);
|
||||||
LLVMValueRef *found = string_map_get(&m->const_strings, key);
|
LLVMValueRef *found = string_map_get(&m->const_strings, key);
|
||||||
if (found != nullptr) {
|
if (found != nullptr) {
|
||||||
@@ -4591,10 +4587,12 @@ LLVMValueRef lb_find_or_add_entity_string_ptr(lbModule *m, String const &str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lbValue lb_find_or_add_entity_string(lbModule *m, String const &str) {
|
lbValue lb_find_or_add_entity_string(lbModule *m, String const &str) {
|
||||||
if (str.len == 0) {
|
LLVMValueRef ptr = nullptr;
|
||||||
return lb_zero(m, t_string);
|
if (str.len != 0) {
|
||||||
|
ptr = lb_find_or_add_entity_string_ptr(m, str);
|
||||||
|
} else {
|
||||||
|
ptr = LLVMConstNull(lb_type(m, t_u8_ptr));
|
||||||
}
|
}
|
||||||
LLVMValueRef ptr = lb_find_or_add_entity_string_ptr(m, str);
|
|
||||||
LLVMValueRef str_len = LLVMConstInt(lb_type(m, t_int), str.len, true);
|
LLVMValueRef str_len = LLVMConstInt(lb_type(m, t_int), str.len, true);
|
||||||
LLVMValueRef values[2] = {ptr, str_len};
|
LLVMValueRef values[2] = {ptr, str_len};
|
||||||
|
|
||||||
@@ -4605,10 +4603,6 @@ lbValue lb_find_or_add_entity_string(lbModule *m, String const &str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lbValue lb_find_or_add_entity_string_byte_slice(lbModule *m, String const &str) {
|
lbValue lb_find_or_add_entity_string_byte_slice(lbModule *m, String const &str) {
|
||||||
if (str.len == 0) {
|
|
||||||
return lb_zero(m, t_u8_slice);
|
|
||||||
}
|
|
||||||
|
|
||||||
LLVMValueRef indices[2] = {llvm_zero(m), llvm_zero(m)};
|
LLVMValueRef indices[2] = {llvm_zero(m), llvm_zero(m)};
|
||||||
LLVMValueRef data = LLVMConstStringInContext(m->ctx,
|
LLVMValueRef data = LLVMConstStringInContext(m->ctx,
|
||||||
cast(char const *)str.text,
|
cast(char const *)str.text,
|
||||||
@@ -4628,7 +4622,12 @@ lbValue lb_find_or_add_entity_string_byte_slice(lbModule *m, String const &str)
|
|||||||
LLVMSetInitializer(global_data, data);
|
LLVMSetInitializer(global_data, data);
|
||||||
LLVMSetLinkage(global_data, LLVMInternalLinkage);
|
LLVMSetLinkage(global_data, LLVMInternalLinkage);
|
||||||
|
|
||||||
LLVMValueRef ptr = LLVMConstInBoundsGEP(global_data, indices, 2);
|
LLVMValueRef ptr = nullptr;
|
||||||
|
if (str.len != 0) {
|
||||||
|
ptr = LLVMConstInBoundsGEP(global_data, indices, 2);
|
||||||
|
} else {
|
||||||
|
ptr = LLVMConstNull(lb_type(m, t_u8_ptr));
|
||||||
|
}
|
||||||
LLVMValueRef len = LLVMConstInt(lb_type(m, t_int), str.len, true);
|
LLVMValueRef len = LLVMConstInt(lb_type(m, t_int), str.len, true);
|
||||||
LLVMValueRef values[2] = {ptr, len};
|
LLVMValueRef values[2] = {ptr, len};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user