瀏覽代碼

Skip unnecessary resize check.

woollybah 6 年之前
父節點
當前提交
2171f3be9b
共有 1 個文件被更改,包括 4 次插入4 次删除
  1. 4 4
      stringbuilder.mod/glue.c

+ 4 - 4
stringbuilder.mod/glue.c

@@ -605,11 +605,11 @@ int bmx_stringbuilder_compare(struct MaxStringBuilder * buf1, struct MaxStringBu
 }
 }
 
 
 void bmx_stringbuilder_leftalign(struct MaxStringBuilder * buf, int length) {
 void bmx_stringbuilder_leftalign(struct MaxStringBuilder * buf, int length) {
-	bmx_stringbuilder_resize(buf, length);
-	
 	if (length == buf->count) {
 	if (length == buf->count) {
 		return;
 		return;
 	} else if (length > buf->count) {
 	} else if (length > buf->count) {
+		bmx_stringbuilder_resize(buf, length);
+
 		int c = length - buf->count;
 		int c = length - buf->count;
 
 
 		BBChar * p = buf->buffer + buf->count;
 		BBChar * p = buf->buffer + buf->count;
@@ -623,14 +623,14 @@ void bmx_stringbuilder_leftalign(struct MaxStringBuilder * buf, int length) {
 }
 }
 
 
 void bmx_stringbuilder_rightalign(struct MaxStringBuilder * buf, int length) {
 void bmx_stringbuilder_rightalign(struct MaxStringBuilder * buf, int length) {
-	bmx_stringbuilder_resize(buf, length);
-
 	if (length == buf->count) {
 	if (length == buf->count) {
 		return;
 		return;
 	} else if (length < buf->count) {
 	} else if (length < buf->count) {
 		int offset = buf->count - length;
 		int offset = buf->count - length;
 		memmove(buf->buffer, buf->buffer + offset, buf->count * sizeof(BBChar));
 		memmove(buf->buffer, buf->buffer + offset, buf->count * sizeof(BBChar));
 	} else {
 	} else {
+		bmx_stringbuilder_resize(buf, length);
+
 		int offset = length - buf->count;
 		int offset = length - buf->count;
 		
 		
 		if (offset == 0) {
 		if (offset == 0) {