Changed BTextView::GetText(), so that the real work is done by the backend. Should be much faster now.
Fixed _BTextGapBuffer_::RealCharAt(), some minor changes git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8408 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
ffec4cb14d
commit
aaae158a2b
@ -1,5 +1,5 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2004, OpenBeOS
|
||||
// Copyright (c) 2001-2004, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
@ -53,7 +53,7 @@ _BTextGapBuffer_::_BTextGapBuffer_()
|
||||
fPasswordMode(false)
|
||||
{
|
||||
fBuffer = (char *)malloc(fExtraCount + fItemCount);
|
||||
fScratchBuffer = (char*)malloc(0);
|
||||
fScratchBuffer = NULL;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
_BTextGapBuffer_::~_BTextGapBuffer_()
|
||||
@ -246,10 +246,50 @@ _BTextGapBuffer_::Text()
|
||||
return fText;
|
||||
}*/
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
_BTextGapBuffer_::GetString(int32 offset, int32 length, char *buffer)
|
||||
{
|
||||
if (buffer == NULL)
|
||||
return;
|
||||
|
||||
int32 textLen = Length();
|
||||
|
||||
if (offset < 0 || offset > (textLen - 1) || length < 1) {
|
||||
buffer[0] = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
length = ((offset + length) > textLen) ? textLen - offset : length;
|
||||
|
||||
bool isStartBeforeGap = (offset < fGapIndex);
|
||||
bool isEndBeforeGap = ((offset + length - 1) < fGapIndex);
|
||||
|
||||
if (isStartBeforeGap == isEndBeforeGap) {
|
||||
char *source = fBuffer + offset;
|
||||
if (!isStartBeforeGap)
|
||||
source += fGapCount;
|
||||
|
||||
memcpy(buffer, source, length);
|
||||
|
||||
} else {
|
||||
// if we are here, it can only be that start is before gap,
|
||||
// and the end is after gap.
|
||||
|
||||
int32 beforeLen = fGapIndex - offset;
|
||||
int32 afterLen = length - beforeLen;
|
||||
|
||||
memcpy(buffer, fBuffer + offset, beforeLen);
|
||||
memcpy(buffer + beforeLen, fBuffer + fGapIndex, afterLen);
|
||||
|
||||
}
|
||||
|
||||
buffer[length] = '\0';
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
char
|
||||
_BTextGapBuffer_::RealCharAt(int32 offset) const
|
||||
{
|
||||
return *(fBuffer + offset);
|
||||
return (offset < fGapIndex) ? fBuffer[offset] : fBuffer[offset + fGapCount];
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
bool
|
||||
|
@ -63,7 +63,7 @@ virtual ~_BTextGapBuffer_();
|
||||
|
||||
|
||||
// char *RealText();
|
||||
// void GetString(int32 offset, int32 length, char *buffer);
|
||||
void GetString(int32 offset, int32 length, char *buffer);
|
||||
// void GetString(int32, int32 *);
|
||||
|
||||
char RealCharAt(int32 offset) const;
|
||||
|
@ -1230,7 +1230,8 @@ BTextView::TextLength() const
|
||||
CALLED();
|
||||
return fText->Length();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void
|
||||
BTextView::GetText(int32 offset, int32 length, char *buffer) const
|
||||
{
|
||||
@ -1238,16 +1239,7 @@ BTextView::GetText(int32 offset, int32 length, char *buffer) const
|
||||
if (buffer == NULL)
|
||||
return;
|
||||
|
||||
int32 textLen = fText->Length();
|
||||
if (offset < 0 || offset > (textLen - 1)) {
|
||||
buffer[0] = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
length = ((offset + length) > textLen) ? textLen - offset : length;
|
||||
for (int32 i = 0; i < length; i++)
|
||||
buffer[i] = (*fText)[i + offset];
|
||||
buffer[length] = '\0';
|
||||
fText->GetString(offset, length, buffer);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user