git » fp-git.git » commit 16fc690

added pl_add

author ecalot
2006-06-13 13:38:47 UTC
committer ecalot
2006-06-13 13:38:47 UTC
parent a1197a86ebc591997df76cf1de523ab4824b9dc5

added pl_add

PR/src/lib/layers/pallist.c +18 -10

diff --git a/PR/src/lib/layers/pallist.c b/PR/src/lib/layers/pallist.c
index dbeb8d9..f8609fd 100644
--- a/PR/src/lib/layers/pallist.c
+++ b/PR/src/lib/layers/pallist.c
@@ -89,18 +89,26 @@ int  pl_hasPriority(tPL* pl, tResourceId resid) {
 }
 
 int  pl_tryAdd(tPL* pl, tResourceId resid, tPriority p) {
-/*	if (p==highPriority) {
-		if (pl->priority_field.object) {
-			if (resourceListCompareId(resid,pl->priority_field.idres)!=0) {
-				tObject* o=pl->priority_field.object;
-				pl->priority_field.object=NULL;
-				pl_add(pl,o,pl->priority_field.idres,lowPriority);
-			}
+	return 0; /* always false, optimization disabled */
+}
+
+int pl_add(tPL* pl, tObject* o, tResourceId resid, tPriority p) {
+	if (p==highPriority) {
+		/* high priority insertion */
+		if (pl->priority_field.object) { /* if there was another object proprized, move it to the list */
+			tObject* obj_old_priority=pl->priority_field.object;
+			if (resourceListCompareId(resid,pl->priority_field.idres)==0) return 0; /* same object, take no action */
+			/* drop the object from the priority field and reinsert it with low priority */
+			pl->priority_field.object=NULL;
+			pl_add(pl,obj_old_priority,pl->priority_field.idres,lowPriority);
 		}
+		/* now, we know there is no object in the priority field, so we insert it */
+		pl->priority_field.object=o;
+		pl->priority_field.idres=resid;
+	} else {
+		/* low priority insertion */
 
 	}
-*/
-
-	return 0;
+	return 1;
 }