Browse Source

Added string and array counters.

woollybah 5 years ago
parent
commit
f667eb75a7
3 changed files with 10 additions and 27 deletions
  1. 2 20
      blitz.mod/blitz_array.c
  2. 6 0
      blitz.mod/blitz_object.c
  3. 2 7
      blitz.mod/blitz_string.c

+ 2 - 20
blitz.mod/blitz_array.c

@@ -44,27 +44,9 @@ BBArray bbEmptyArray={
 
 //***** Note: Only used by ref counting GC.
 static void bbArrayFree( BBObject *o ){
-#ifdef BB_GC_RC
-	int k;
-	BBObject **p;
-	BBArray *arr=(BBArray*)o;
-	
-	if( arr==&bbEmptyArray ){
-		//arr->refs=BBGC_MANYREFS;
-		return;
+	if (bbCountInstances) {
+		bbAtomicAdd(&bbArrayClass.instance_count, -1);
 	}
-
-	switch( arr->type[0] ){
-	case ':':case '$':case '[':
-		p=(BBObject**)BBARRAYDATA(arr,arr->dims);
-		for( k=arr->scales[0];k>0;--k ){
-			BBObject *o=*p++;
-			//BBDECREFS( o );
-		}
-		break;
-	}
-	bbGCDeallocObject( arr,BBARRAYSIZE( arr->size,arr->dims ) );
-#endif
 }
 
 static int arrayCellSize(const char * type, unsigned short data_size, int * flags) {

+ 6 - 0
blitz.mod/blitz_object.c

@@ -138,6 +138,12 @@ void bbObjectDumpInstanceCounts(char * buf, int size, int includeZeros) {
 	int offset = 0;
 	BBClass ** classes = bbObjectRegisteredTypes(&count);
 	offset += snprintf(buf, size, "=== Instance count dump (%4d) ===\n", count);
+	if (bbStringClass.instance_count > 0 || includeZeros) {
+		offset += snprintf(buf + offset, size - offset, "%s\t%d\n", bbStringClass.debug_scope->name, bbStringClass.instance_count);
+	}
+	if (bbArrayClass.instance_count > 0 || includeZeros) {
+		offset += snprintf(buf + offset, size - offset, "%s\t%d\n", bbArrayClass.debug_scope->name, bbArrayClass.instance_count);
+	}
 	for (int i = 0; i < count; i++) {
 		BBClass * clas = classes[i];
 		if (offset < size && (clas->instance_count > 0 || includeZeros)) {

+ 2 - 7
blitz.mod/blitz_string.c

@@ -103,14 +103,9 @@ static int charsEqual( unsigned short *a,unsigned short *b,int n ){
 
 //***** Note: Not called in THREADED mode.
 static void bbStringFree( BBObject *o ){
-#ifdef BB_GC_RC
-	BBString *str=(BBString*)o;
-	if( str==&bbEmptyString ){
-		//str->refs=BBGC_MANYREFS;
-		return;
+	if (bbCountInstances) {
+		bbAtomicAdd(&bbStringClass.instance_count, -1);
 	}
-	bbGCDeallocObject( str,sizeof(BBString)+str->length*sizeof(BBChar) );
-#endif
 }
 
 BBString *bbStringNew( int len ){