blueloveTH 1 rok temu
rodzic
commit
1c9bd1836c

+ 2 - 2
include/pocketpy/common/str.h

@@ -56,8 +56,8 @@ int pkpy_Str__unicode_index_to_byte(const pkpy_Str* self, int i);
 int pkpy_Str__byte_index_to_unicode(const pkpy_Str* self, int n);
 int pkpy_Str__index(const pkpy_Str* self, const pkpy_Str* sub, int start);
 int pkpy_Str__count(const pkpy_Str* self, const pkpy_Str* sub);
-c11_array/* T=c11_string */ pkpy_Str__split(const pkpy_Str* self, char sep);
-c11_array/* T=c11_string */ pkpy_Str__split2(const pkpy_Str* self, const pkpy_Str* sep);
+c11_vector/* T=c11_string */ pkpy_Str__split(const pkpy_Str* self, char sep);
+c11_vector/* T=c11_string */ pkpy_Str__split2(const pkpy_Str* self, const pkpy_Str* sep);
 
 #ifdef __cplusplus
 }

+ 4 - 4
include/pocketpy/common/str.hpp

@@ -192,24 +192,24 @@ struct Str: pkpy_Str {
     }
 
     vector<std::string_view> split(const Str& sep) const{
-        c11_array/* T=c11_string */ res = pkpy_Str__split2(this, &sep);
+        c11_vector/* T=c11_string */ res = pkpy_Str__split2(this, &sep);
         vector<std::string_view> retval(res.count);
         for(int i = 0; i < res.count; i++){
             c11_string tmp = c11__getitem(c11_string, &res, i);
             retval[i] = std::string_view(tmp.data, tmp.size);
         }
-        c11_array__dtor(&res);
+        c11_vector__dtor(&res);
         return retval;
     }
 
     vector<std::string_view> split(char sep) const{
-        c11_array/* T=c11_string */ res = pkpy_Str__split(this, sep);
+        c11_vector/* T=c11_string */ res = pkpy_Str__split(this, sep);
         vector<std::string_view> retval(res.count);
         for(int i = 0; i < res.count; i++){
             c11_string tmp = c11__getitem(c11_string, &res, i);
             retval[i] = std::string_view(tmp.data, tmp.size);
         }
-        c11_array__dtor(&res);
+        c11_vector__dtor(&res);
         return retval;
     }
 

+ 0 - 1
include/pocketpy/common/vector.h

@@ -27,7 +27,6 @@ void c11_vector__dtor(c11_vector* self);
 c11_vector c11_vector__copy(const c11_vector* self);
 void* c11_vector__at(c11_vector* self, int index);
 void c11_vector__reserve(c11_vector* self, int capacity);
-c11_array c11_vector__as_array(c11_vector* self);
 
 #define c11__getitem(T, self, index) ((T*)(self)->data)[index]
 #define c11__setitem(T, self, index, value) ((T*)(self)->data)[index] = value;

+ 4 - 4
src/common/str.c

@@ -351,7 +351,7 @@ int pkpy_Str__count(const pkpy_Str *self, const pkpy_Str *sub){
     return cnt;
 }
 
-c11_array/* T=c11_string */ pkpy_Str__split(const pkpy_Str *self, char sep){
+c11_vector/* T=c11_string */ pkpy_Str__split(const pkpy_Str *self, char sep){
     c11_vector retval;
     c11_vector__ctor(&retval, sizeof(c11_string));
     const char* data = pkpy_Str__data(self);
@@ -370,10 +370,10 @@ c11_array/* T=c11_string */ pkpy_Str__split(const pkpy_Str *self, char sep){
         c11_string tmp = {data + i, self->size - i};
         c11_vector__push(c11_string, &retval, tmp);
     }
-    return c11_vector__as_array(&retval);
+    return retval;
 }
 
-c11_array/* T=c11_string */ pkpy_Str__split2(const pkpy_Str *self, const pkpy_Str *sep){
+c11_vector/* T=c11_string */ pkpy_Str__split2(const pkpy_Str *self, const pkpy_Str *sep){
     c11_vector retval;
     c11_vector__ctor(&retval, sizeof(c11_string));
     int start = 0;
@@ -387,5 +387,5 @@ c11_array/* T=c11_string */ pkpy_Str__split2(const pkpy_Str *self, const pkpy_St
     }
     c11_string tmp = {data + start, self->size - start};
     if(tmp.size != 0) c11_vector__push(c11_string, &retval, tmp);
-    return c11_vector__as_array(&retval);
+    return retval;
 }

+ 0 - 8
src/common/vector.c

@@ -60,11 +60,3 @@ void c11_vector__reserve(c11_vector* self, int capacity){
     self->data = realloc(self->data, self->elem_size * self->capacity);
 }
 
-c11_array c11_vector__as_array(c11_vector* self){
-    c11_array retval = {
-        .data = self->data,
-        .count = self->count,
-        .elem_size = self->elem_size,
-    };
-    return retval;
-}