[Scummvm-git-logs] scummvm master -> 02ca64a0190f55281b37f55ba9eb0899853bc257

sev- noreply at scummvm.org
Fri Feb 28 16:39:57 UTC 2025


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
02ca64a019 DIECTOR: LINGO: Fix b_add documentation and take into account sorted list property


Commit: 02ca64a0190f55281b37f55ba9eb0899853bc257
    https://github.com/scummvm/scummvm/commit/02ca64a0190f55281b37f55ba9eb0899853bc257
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2025-02-28T17:39:22+01:00

Commit Message:
DIECTOR: LINGO: Fix b_add documentation and take into account sorted list property

Changed paths:
    engines/director/lingo/lingo-builtins.cpp


diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index 8eb649dd23d..e6fe15da353 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -632,9 +632,30 @@ void LB::b_value(int nargs) {
 // Lists
 ///////////////////
 void LB::b_add(int nargs) {
-	// FIXME: when a list is "sorted", add should insert based on
-	// the current ordering. otherwise, append to the end.
-	LB::b_append(nargs);
+	Datum value = g_lingo->pop();
+	Datum list = g_lingo->pop();
+
+	TYPECHECK(list, ARRAY);
+
+	// If the list is sorted, keep the sort
+	if (list.u.farr->_sorted) {
+		if (list.u.farr->arr.empty()) {
+			list.u.farr->arr.push_back(value);
+		} else {
+			// TODO: We'd better do a binary search here
+			uint pos = list.u.farr->arr.size();
+			for (uint i = 0; i < list.u.farr->arr.size(); i++) {
+				if (list.u.farr->arr[i] > value) { // We are using Datum::compareTo() here
+					pos = i;
+					break;
+				}
+			}
+			list.u.farr->arr.insert_at(pos, value);
+		}
+	} else {
+		list.u.farr->arr.push_back(value);
+		list.u.farr->_sorted = false;		// Drop the sorted flag
+	}
 }
 
 void LB::b_addAt(int nargs) {
@@ -687,22 +708,8 @@ void LB::b_append(int nargs) {
 
 	TYPECHECK(list, ARRAY);
 
-	if (list.u.farr->_sorted) {
-		if (list.u.farr->arr.empty())
-			list.u.farr->arr.push_back(value);
-		else {
-			uint pos = list.u.farr->arr.size();
-			for (uint i = 0; i < list.u.farr->arr.size(); i++) {
-				if (list.u.farr->arr[i].asInt() > value.asInt()) {
-					pos = i;
-					break;
-				}
-			}
-			list.u.farr->arr.insert_at(pos, value);
-		}
-	} else {
-		list.u.farr->arr.push_back(value);
-	}
+	list.u.farr->arr.push_back(value);
+	list.u.farr->_sorted = false;		// Drop the sorted flag
 }
 
 void LB::b_count(int nargs) {




More information about the Scummvm-git-logs mailing list