﻿id	summary	reporter	owner	description	type	status	milestone	component	version	severity	resolution	keywords	cc
2120	Improvements to _GuiCtrlListView_DeleteAllItems	Beege	guinness	"I was noticing how deleting all items it a autoit listview took almost 3x longer than it takes to add them. I came up with the following improvements below.

{{{
Time Results:
_GUICtrlListView_DeleteAllItems = 3592.88679294215
_GUICtrlListView_DeleteAllItems2 = 587.438691126462
}}}

{{{
#include <GuiListView.au3>
Opt('MustDeclareVars', 1)

Local $hGUI = GUICreate('Listview Delete All Items', 250, 400)
Local $ListView = GUICtrlCreateListView('Items', 0, 0, 248, 398)
GUISetState()

For $i = 1 To 10000
	GUICtrlCreateListViewItem($i, $ListView)
Next
Local $time = TimerInit()
_GUICtrlListView_DeleteAllItems($ListView)
ConsoleWrite('_GUICtrlListView_DeleteAllItems = ' & TimerDiff($time) & @LF)

For $i = 1 To 10000
	GUICtrlCreateListViewItem($i, $ListView)
Next
Local $time = TimerInit()
_GUICtrlListView_DeleteAllItems2($ListView)
ConsoleWrite('_GUICtrlListView_DeleteAllItems2 = ' & TimerDiff($time) & @LF)

Do
Until GUIGetMsg() = -3

Func _GUICtrlListView_DeleteAllItems2($hWnd)
	If $Debug_LV Then __UDF_ValidateClassName($hWnd, $__LISTVIEWCONSTANT_ClassName)
	If _GUICtrlListView_GetItemCount($hWnd) = 0 Then Return True
	If IsHWnd($hWnd) Then
		Return _SendMessage($hWnd, $LVM_DELETEALLITEMS) <> 0
	Else
		Local $ctrlID
		Local $tItem = DllStructCreate($tagLVITEM)
		Local $pItem = DllStructGetPtr($tItem)
		Local $LV_Msg = $LVM_GETITEMA
		If _GUICtrlListView_GetUnicodeFormat($hWnd) Then $LV_Msg = $LVM_GETITEMW
		DllStructSetData($tItem, ""Mask"", $LVIF_PARAM)
		GUICtrlSendMsg($hWnd, 11, 0, 0);$WM_SETREDRAW
		For $index = _GUICtrlListView_GetItemCount($hWnd) - 1 To 0 Step -1
			DllStructSetData($tItem, ""Item"", $index)
			GUICtrlSendMsg($hWnd, $LV_Msg, 0, $pItem)
			$ctrlID = DllStructGetData($tItem, ""Param"")
			If $ctrlID Then GUICtrlDelete($ctrlID)
		Next
		GUICtrlSendMsg($hWnd, 11, 1, 0);$WM_SETREDRAW
		If _GUICtrlListView_GetItemCount($hWnd) = 0 Then Return True
	EndIf
	Return False
EndFunc   ;==>__GUICtrlListView_DeleteAllItems
}}}



"	Feature Request	closed	3.3.9.5	Standard UDFs		None	Completed	_GuiCtrlListView_DeleteAllItems	
