ScintillaNET icon indicating copy to clipboard operation
ScintillaNET copied to clipboard

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

Open george-tsiros opened this issue 3 years ago • 0 comments

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" ?

george-tsiros avatar Mar 12 '21 08:03 george-tsiros