Dylan Smith : richedit: Avoid duplication in make string functions using ME_MakeStringB.
Alexandre Julliard
julliard at winehq.org
Mon Feb 9 10:29:29 CST 2009
Module: wine
Branch: master
Commit: 4b7e8f185b223c7c712f4102b91ef64877a58053
URL: http://source.winehq.org/git/wine.git/?a=commit;h=4b7e8f185b223c7c712f4102b91ef64877a58053
Author: Dylan Smith <dylan.ah.smith at gmail.com>
Date: Sat Feb 7 13:20:55 2009 -0500
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.
---
dlls/riched20/editor.h | 1 -
dlls/riched20/string.c | 56 ++++++++++++++++++-----------------------------
2 files changed, 22 insertions(+), 35 deletions(-)
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index e06a86d..90dcd2a 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -91,7 +91,6 @@ const char *ME_GetDITypeName(ME_DIType type);
ME_String *ME_MakeString(LPCWSTR szText);
ME_String *ME_MakeStringN(LPCWSTR szText, int nMaxChars);
ME_String *ME_MakeStringR(WCHAR cRepeat, int nMaxChars);
-ME_String *ME_MakeStringB(int nMaxChars);
ME_String *ME_StrDup(const ME_String *s);
void ME_DestroyString(ME_String *s);
void ME_AppendString(ME_String *s1, const ME_String *s2);
diff --git a/dlls/riched20/string.c b/dlls/riched20/string.c
index 67b4d9c..d8852fb 100644
--- a/dlls/riched20/string.c
+++ b/dlls/riched20/string.c
@@ -18,61 +18,49 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
-#include "editor.h"
+#include "editor.h"
WINE_DEFAULT_DEBUG_CHANNEL(richedit);
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);
- 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);
- lstrcpyW(s->szData, szText);
+ s->szData[s->nLen] = 0;
return s;
}
ME_String *ME_MakeStringN(LPCWSTR szText, int 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);
- /* Native allows NUL chars */
- memmove(s->szData, szText, s->nLen * sizeof(WCHAR));
- s->szData[s->nLen] = 0;
+ ME_String *s = ME_MakeStringB(nMaxChars);
+ /* Native allows NULL chars */
+ memcpy(s->szData, szText, s->nLen * sizeof(WCHAR));
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)
-{ /* Make a string by repeating a char nMaxChars times */
+{
int i;
- 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);
-
- for (i = 0;i<nMaxChars;i++)
+ ME_String *s = ME_MakeStringB(nMaxChars);
+ for (i = 0; i < nMaxChars; i++)
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;
}
More information about the wine-cvs
mailing list