Commit 4b7e8f18 authored by Dylan Smith's avatar Dylan Smith Committed by Alexandre Julliard

richedit: Avoid duplication in make string functions using ME_MakeStringB.

I found that ME_MakeStringB was previously unused, and that the other ME_MakeString functions repeated code that was already in ME_MakeStringB. Making ME_MakeStringB static and using it to avoid duplicate code seemed like a better idea than removing the function.
parent f53f40bc
...@@ -91,7 +91,6 @@ const char *ME_GetDITypeName(ME_DIType type); ...@@ -91,7 +91,6 @@ const char *ME_GetDITypeName(ME_DIType type);
ME_String *ME_MakeString(LPCWSTR szText); ME_String *ME_MakeString(LPCWSTR szText);
ME_String *ME_MakeStringN(LPCWSTR szText, int nMaxChars); ME_String *ME_MakeStringN(LPCWSTR szText, int nMaxChars);
ME_String *ME_MakeStringR(WCHAR cRepeat, int nMaxChars); ME_String *ME_MakeStringR(WCHAR cRepeat, int nMaxChars);
ME_String *ME_MakeStringB(int nMaxChars);
ME_String *ME_StrDup(const ME_String *s); ME_String *ME_StrDup(const ME_String *s);
void ME_DestroyString(ME_String *s); void ME_DestroyString(ME_String *s);
void ME_AppendString(ME_String *s1, const ME_String *s2); void ME_AppendString(ME_String *s1, const ME_String *s2);
......
...@@ -24,55 +24,43 @@ WINE_DEFAULT_DEBUG_CHANNEL(richedit); ...@@ -24,55 +24,43 @@ WINE_DEFAULT_DEBUG_CHANNEL(richedit);
static int ME_GetOptimalBuffer(int nLen) static int ME_GetOptimalBuffer(int nLen)
{ {
return ((2*nLen+1)+128)&~63; /* FIXME: This seems wasteful for tabs and end of lines strings,
* since they have a small fixed length. */
return ((sizeof(WCHAR) * nLen) + 128) & ~63;
} }
ME_String *ME_MakeString(LPCWSTR szText) /* Create a buffer (uninitialized string) of size nMaxChars */
static ME_String *ME_MakeStringB(int nMaxChars)
{ {
ME_String *s = ALLOC_OBJ(ME_String); ME_String *s = ALLOC_OBJ(ME_String);
s->nLen = lstrlenW(szText);
s->nBuffer = ME_GetOptimalBuffer(s->nLen+1); s->nLen = nMaxChars;
s->nBuffer = ME_GetOptimalBuffer(s->nLen + 1);
s->szData = ALLOC_N_OBJ(WCHAR, s->nBuffer); s->szData = ALLOC_N_OBJ(WCHAR, s->nBuffer);
lstrcpyW(s->szData, szText); s->szData[s->nLen] = 0;
return s; return s;
} }
ME_String *ME_MakeStringN(LPCWSTR szText, int nMaxChars) ME_String *ME_MakeStringN(LPCWSTR szText, int nMaxChars)
{ {
ME_String *s = ALLOC_OBJ(ME_String); ME_String *s = ME_MakeStringB(nMaxChars);
/* Native allows NULL chars */
s->nLen = nMaxChars; memcpy(s->szData, szText, s->nLen * sizeof(WCHAR));
s->nBuffer = ME_GetOptimalBuffer(s->nLen+1);
s->szData = ALLOC_N_OBJ(WCHAR, s->nBuffer);
/* Native allows NUL chars */
memmove(s->szData, szText, s->nLen * sizeof(WCHAR));
s->szData[s->nLen] = 0;
return s; return s;
} }
ME_String *ME_MakeString(LPCWSTR szText)
{
return ME_MakeStringN(szText, lstrlenW(szText));
}
/* Make a string by repeating a char nMaxChars times */
ME_String *ME_MakeStringR(WCHAR cRepeat, int nMaxChars) ME_String *ME_MakeStringR(WCHAR cRepeat, int nMaxChars)
{ /* Make a string by repeating a char nMaxChars times */ {
int i; int i;
ME_String *s = ALLOC_OBJ(ME_String); ME_String *s = ME_MakeStringB(nMaxChars);
for (i = 0; i < nMaxChars; i++)
s->nLen = nMaxChars;
s->nBuffer = ME_GetOptimalBuffer(s->nLen+1);
s->szData = ALLOC_N_OBJ(WCHAR, s->nBuffer);
for (i = 0;i<nMaxChars;i++)
s->szData[i] = cRepeat; s->szData[i] = cRepeat;
s->szData[s->nLen] = 0;
return s;
}
ME_String *ME_MakeStringB(int nMaxChars)
{ /* Create a buffer (uninitialized string) of size nMaxChars */
ME_String *s = ALLOC_OBJ(ME_String);
s->nLen = nMaxChars;
s->nBuffer = ME_GetOptimalBuffer(s->nLen+1);
s->szData = ALLOC_N_OBJ(WCHAR, s->nBuffer);
s->szData[s->nLen] = 0;
return s; return s;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment