jacobslusser / ScintillaNET

A Windows Forms control, wrapper, and bindings for the Scintilla text editor.
MIT License
963 stars 243 forks source link

DirectMessage(int, IntPtr, IntPtr) at call sites always has new IntPtr(int) #507

Open george-tsiros opened 3 years ago

george-tsiros commented 3 years ago

wouldn't it be better if instead of calling the IntPtr .ctor (twice) at every call site we let DirectMessage create the IntPtr ?

private static IntPtr DirectMessage (IntPtr sciPtr, int msg, IntPtr wParam, IntPtr lParam) {
    // Like Win32 SendMessage but directly to Scintilla
    var result = _DIRECT_FUNCTION(sciPtr, msg, wParam, lParam);
    return result;
}

public int WordStartPosition (int position, bool onlyWordCharacters) {
    var onlyWordChars = (onlyWordCharacters ? new IntPtr(1) : IntPtr.Zero);
    position = Helpers.Clamp(position, 0, TextLength);
    position = Lines.CharToBytePosition(position);
    position = DirectMessage(NativeMethods.SCI_WORDSTARTPOSITION, new IntPtr(position), onlyWordChars).ToInt32();
    return Lines.ByteToCharPosition(position);
}

vs

private static IntPtr DirectMessage (IntPtr sciPtr, int msg, int wParam, int lParam) {
    // Like Win32 SendMessage but directly to Scintilla
    var result = _DIRECT_FUNCTION(sciPtr, msg, new IntPtr(wParam), new IntPtr(lParam));
    return result;
}

public int WordStartPosition (int position, bool onlyWordCharacters) {
    var onlyWordChars = onlyWordCharacters ? 1 : 0;
    position = Helpers.Clamp(position, 0, TextLength);
    position = Lines.CharToBytePosition(position);
    position = DirectMessage(NativeMethods.SCI_WORDSTARTPOSITION, position, onlyWordChars).ToInt32();
    return Lines.ByteToCharPosition(position);
}

edit: how can i label this as "unimportant" ?