Fixed a crash when running beshare with our BTextView (thanks to Andrew Bachmann for reporting), though it's a bit hackish, added some printfs to TextView.cpp to help finding/fixing bugs, a small optimization to WidthBuffer. Should convert and commit WidthBuffer's tests to cppunit tests sooner or later.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6989 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2004-03-15 07:19:27 +00:00
parent 80127f8edb
commit 7446a252ed
2 changed files with 209 additions and 56 deletions
File diff suppressed because it is too large Load Diff
+15 -7
View File
@@ -28,6 +28,8 @@
#include <cstdio>
//#define USE_DANO_WIDTHBUFFER
const uint32 kTableCount = 128;
struct hashed_escapement
@@ -171,10 +173,12 @@ _BWidthBuffer_::FindTable(const BFont *inStyle, int32 *outIndex)
int32 tableIndex = -1;
for (int32 i = 0; i < fItemCount; i++) {
#if B_BEOS_VERSION_DANO
#ifdef USE_DANO_WIDTHBUFFER
if (*inStyle == fBuffer[i].font) {
#else
if (fontSize == fBuffer[i].fontSize && fontCode == fBuffer[i].fontCode) {
if (fontSize == fBuffer[i].fontSize
&& fontCode == fBuffer[i].fontCode) {
#endif
tableIndex = i;
break;
@@ -196,12 +200,14 @@ _BWidthBuffer_::InsertTable(const BFont *font)
{
_width_table_ table;
hashed_escapement *deltas = new hashed_escapement[kTableCount];
#if B_BEOS_VERSION_DANO
table.font = font;
#if USE_DANO_WIDTHBUFFER
table.font = *font;
#else
table.fontSize = font->Size();
table.fontCode = font->FamilyAndStyle();
#endif
table.hashCount = 0;
table.tableCount = kTableCount;
table.widths = deltas;
@@ -237,8 +243,8 @@ _BWidthBuffer_::GetEscapement(uint32 value, int32 index, float *escapement)
while ((found = widths[hashed].code) != (uint32)-1) {
if (found == value)
break;
hashed++;
if (hashed >= (uint32)table->tableCount)
if (++hashed >= (uint32)table->tableCount)
hashed = 0;
DEBUG_ONLY(iterations++;)
}
@@ -311,12 +317,13 @@ _BWidthBuffer_::HashEscapements(const char *inText, int32 numChars, int32 textLe
if (++hashed >= (uint32)table->tableCount)
hashed = 0;
}
if (found == (uint32)-1) {
// The value is not in the table. Add it.
widths[hashed].code = value;
widths[hashed].escapement = escapements[charCount];
table->hashCount++;
}
// We always keep some free space in the hash table
// TODO: Not sure how much space, currently we double
// the current size when hashCount is at least 2/3 of
@@ -351,6 +358,7 @@ _BWidthBuffer_::HashEscapements(const char *inText, int32 numChars, int32 textLe
widths = newWidths;
}
}
}
charCount++;
offset += charLen;
} while (offset < textLen);